【发布时间】:2020-03-25 13:18:19
【问题描述】:
这是一个正确的语法,并且 100% 有效。但是我的讲师希望这种语法的作品没有“break”功能但仍然使用“do-while”功能。有人可以帮助我吗?我被卡住了:(
代码如下:
import java.util.Scanner;
public class NewClass {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[] bil = new int[10];
int x=0;
while(x!=10){
System.out.print("Input ke-"+(x+1)+" : ");
bil[x]=input.nextInt();
if(bil[x]==0) {
x++;
break;
}
x++;
}
System.out.println("==============================");
for(int j=0; j<x; j++){
System.out.println("Data ke-"+(j+1)+": "+bil[j]);
}
}
}
【问题讨论】:
-
您没有使用 do-while 循环。你只是在使用 while 循环
-
你能修复这个程序吗? :(@Steephen
标签: java arrays input output do-while