如何使用while循环在java中打印第一行的109876和第二行的10987?
如何使用while循环在java中打印第一行的109876和第二行的10987?如何从第一行更改为第二行?请尝试以下代码:如何使用while循环在java中打印第一行的109876和第二行的10987?,java,while-loop,Java,While Loop,如何使用while循环在java中打印第一行的109876和第二行的10987?如何从第一行更改为第二行?请尝试以下代码: public class Test { public static void main(String args[]) { int x = 10; int i = 0; int n = 6; while(i++ < n) { while( i++ < n ) { System.out.print(x-- + " ");
public class Test {
public static void main(String args[]) {
int x = 10;
int i = 0;
int n = 6;
while(i++ < n) {
while( i++ < n ) {
System.out.print(x-- + " ");
}
System.out.println("\n");
x = 10;
i = 0;
n = n-1;
}
}
}
公共类测试{
公共静态void main(字符串参数[]){
int x=10;
int i=0;
int n=6;
while(i++
输出:
109876
10987
1098
109
10需要使用两个while循环
public static void main(String[] args) {
int i =10;
int count =5;
while(i>=count){
int j=i;
while(j>count){
System.out.print(j+" ");
j--;
}
System.out.println();
count++;
}
}
输出
10 9 8 7 6
10 9 8 7
10 9 8
10 9
10
使用while循环:
public class Test {
public static void main(String args[]) {
int x = 10;
int i = 4;
while(i<=4 && i >= 0){
int j=0;
while(j<=i){
int h = (x - j);
System.out.print(h + " ");
j++;
}
i--;
System.out.print("\n");
if(i<=2)break;
}
}
}
如果要按以下方式输出:
10 9 8 7 6
10 9 8 7
10 9 8
10 9
10
您需要注释掉
,如果(i您试过什么吗?publicstaticvoidmain(String[]args){//TODO自动生成的方法存根int i=10;而(i>=1){System.out.print(i+);i=i-1;}int j=10;而(j>=2){System.out.print(“\n”+j);j=j-1;}你可以检查下面的代码。说i>2
并删除break
不是更好吗?好的,我会更新它:DOP使用了两个while循环(在对问题的评论中)。重要的是它们必须嵌套。你做到了。;-)
10 9 8 7 6
10 9 8 7
10 9 8 7 6
10 9 8 7
10 9 8
10 9
10