JAVA编写一个简单的程序,输入下面图形中各行最多的*号数值,实现输出下面的图形: * * * * * * * * * * * * * * * * *
时间: 2023-11-14 10:04:49 浏览: 51
以下是实现该程序的Java代码:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] nums = new int[5];
for (int i = 0; i < 5; i++) {
nums[i] = scanner.nextInt();
}
for (int i = 0; i < nums[0]; i++) {
System.out.print("* ");
}
System.out.println();
for (int i = 0; i < nums[1]; i++) {
System.out.print(" ");
System.out.print("* ");
if (i == nums[1] - 1) {
System.out.println();
}
}
for (int i = 0; i < nums[2]; i++) {
System.out.print(" ");
System.out.print("* ");
if (i == nums[2] - 1) {
System.out.println();
}
}
for (int i = 0; i < nums[3]; i++) {
System.out.print(" ");
System.out.print("* ");
if (i == nums[3] - 1) {
System.out.println();
}
}
for (int i = 0; i < nums[4]; i++) {
System.out.print("* ");
}
}
}
```
输入示例:
```
5
3
1
3
5
```
输出示例:
```
* * * * *
* * *
*
* * *
* * * * *
```
阅读全文