* * * * * * * * * * * * * * *用java编写程序编写出此图案
时间: 2023-10-06 08:11:33 浏览: 42
以下是用Java编写程序输出该图案的代码:
```java
public class Pattern {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}
```
运行这段代码,将输出所需的图案:
```
*
* *
* * *
* * * *
* * * * *
```
相关问题
编写一个Java输出* * * * * * * * *
你可以使用循环语句来编写一个Java程序输出一行星号的图案。以下是一个示例代码:
```java
public class StarPattern {
public static void main(String[] args) {
int numStars = 10; // 设置星号的数量
for (int i = 0; i < numStars; i++) {
System.out.print("* "); // 输出星号和空格
}
}
}
```
这段代码会输出10个星号,每个星号后面有一个空格。你可以根据需要修改`numStars`的值来改变星号的数量。
1. 编写程序,打印以下图案: ***** *** *
以下是C语言实现的代码:
```c
#include <stdio.h>
int main() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9 - 2 * i; j++) {
printf("*");
}
printf("\n");
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 7 + 2 * i; j++) {
printf(" ");
}
for (int j = 0; j < 2 * i + 3; j++) {
printf("*");
}
printf("\n");
}
printf(" *\n");
return 0;
}
```
输出结果为:
```
*********
*******
*****
***
*
```
以下是Java实现的代码:
```java
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9 - 2 * i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 7 + 2 * i; j++) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 3; j++) {
System.out.print("*");
}
System.out.println();
}
System.out.println(" *");
}
}
```
输出结果为:
```
*********
*******
*****
***
*
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)