【发布时间】:2017-05-03 05:57:38
【问题描述】:
当我运行代码时,我的输入字符串不会出现。首先它说当我把它放在我的 Main 方法中时它是不可用的。在我将它从我的 Main 方法中取出并将其放在 Public 类中之后,无法使用的问题就消失了。但是在运行代码时它仍然不会出现。
public class Number0to9 {
public static String input;
public static void main(String[] args) {
tryagain: while (true) {
System.out.print("Type a number between 0 and 9 : ");
Scanner scan = new Scanner(System.in);
int x = scan.nextInt();
int output = x;
input = "You entered number: ";
switch (x) {
case 0:
input += output;
break tryagain;
case 1:
input += output;
break tryagain;
case 2:
input += output;
break tryagain;
case 3:
input += output;
break tryagain;
case 4:
input += output;
break tryagain;
case 5:
input += output;
break tryagain;
case 6:
input += output;
break tryagain;
case 7:
input += output;
break tryagain;
case 8:
input += output;
break tryagain;
case 9:
input += output;
break tryagain;
default:
System.out.println("Your number was bigger than 9");
break;
}
}
}
}
【问题讨论】:
-
非常不清楚你在问什么 - 如果你需要在输出中看到一些东西,你最好打印出来......请查看帖子中的 minimal reproducible example 指导和 edit 代码以清楚地展示问题(即
switch不太可能与您的问题相关,尽管在标题和大量代码中提到了它)
标签: java string switch-statement