我需要根据用户输入显示以下系列
示例:如果用户输入数字 5,则预期输出将为
54321
5432
543
54
5
public static void main(String args[]) throws Exception {
int n;
boolean quit = false;
BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number :");
n = sc.nextInt();
System.out.println("The Series is:");
for(int i=n;i>=1;i--){
for(int j=n; j<=i; j++){
System.out.print(j);
}
}
System.out.println("");
}
最佳答案
假设您毫无问题地获得了所需的整数,那么序列的算法可能如下所示:
int f = 5;
int k = f;
while (k > 0) {
for (int i = 0; i < k; i++) {
System.out.println(f - i);
}
k--;
System.out.println("....");
}
正在打印您想要的序列: 5 4 3 2 1 .... 5 4 3 2 .... 5 4 3 .... 5 4 .... 5 ....
关于java - 通过用户输入在java中打印一系列数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32845502/