利用Scanner输入整数,存值作为for循环条件的判断。代码如下:
public class Test11 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入整数:");
int num = scanner.nextInt();
for (int i = 0; i < num; i++) {
for (int j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
输出结果: