关键词:循环语句
题目:
问题描述
编写一个程序,首先输入一个整数,例如5,然后在屏幕上显示如下的图形(5表示行数):
* * * * *
* * * *
* * *
* *
*
代码:
public class Main {
public static void main(String[] args) {
java.util.Scanner s=new java.util.Scanner(System.in);
int a=s.nextInt();
for(int i=a;i>0;i--){
for(int j=i;j>0;j--){
System.out.print("*"+" ");
}
System.out.println();
}
}
}

本文展示了一个使用Java编写的程序示例,该程序通过循环语句实现了一种倒三角形的星号打印效果。用户可以输入一个整数,程序将根据这个整数的大小,从上至下逐行减少星号的数量,形成一个倒置的三角形。
254

被折叠的 条评论
为什么被折叠?



