【发布时间】:2018-12-04 05:50:37
【问题描述】:
我无法使用 for 循环在 Java 程序中打印以下模式。 请就此问题寻求帮助。
5
54
543
5432
54321
代码
Scanner sc = new Scanner(System.in); // Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = rows; i >= 1; i--) {
for (int j = 1; j < i; j++) {
System.out.print(" ");
}
}
【问题讨论】:
-
请贴出你写的代码来尝试解决这个问题
-
Stack Overflow 不是免费的编码作业服务。请向我们展示您已经尝试过的代码。
-
您好,欢迎来到 StackOverflow。请花一些时间阅读帮助页面,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。更重要的是,请阅读Stack Overflow question checklist。您可能还想了解Minimal, Complete, and Verifiable Examples。格式化您的问题,并向我们展示您迄今为止的工作。
-
导入 java.util.Scanner;公共类 PattrenClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //从用户获取行值 System.out.println("你想要这个模式有多少行?"); int 行 = sc.nextInt(); System.out.println("这是你的模式……!!!"); for (int i = rows; i >= 1; i--) { for (int j = 1; j
-
请edit您的问题包含代码。 (在 cmets 中读起来有点困难)