Java 开关状态中的孤立案例错误
我用java写了一个小程序 用户输入一个数字以得到他的乘法表 然后键入该表的最大长度 但在第三个案例(案例r)中,我得到了一个错误孤立案例 在我看来,这是一个干净的代码Java 开关状态中的孤立案例错误,java,Java,我用java写了一个小程序 用户输入一个数字以得到他的乘法表 然后键入该表的最大长度 但在第三个案例(案例r)中,我得到了一个错误孤立案例 在我看来,这是一个干净的代码 public class JavaApplication2 { public static void main(String[] args) throws IOException { System.out.println("Multiplication Table v1.0"); System.out.prin
public class JavaApplication2 {
public static void main(String[] args) throws IOException
{
System.out.println("Multiplication Table v1.0");
System.out.println("Developped By Roy Jalbout");
System.out.println("-------------------------");
System.out.println("Type 'E' To Quit The Program\nType 'H' To Read The Help File\nType 'R' To Run The Program");
char act = (char)System.in.read();
switch (act) {
case 'e':
case 'E':
System.exit(0);
break;
case 'h':
case 'H':
System.out.println("The Multiplication Table Version 1.0 Developped By Roy Jalbout is A Simple Program All you have to do is to choose the number that you want to get his multiplication table and then choose the maximum lenght of that table");
System.out.println("----------------------------------");
System.out.println("Type back to go to the main thread");
String mainthread = scn.next();
if ("back".equals(mainthread)){
JavaApplication2.main(args);
break;
case 'r':
case 'R':
Scanner scn = new Scanner(System.in);
System.out.print("Enter A Number To Get His Multiplication Table : ");
int num = scn.nextInt();
System.out.print("Enter The Max Number Of The Multiplication Table : ");
int max = scn.nextInt();
int b=1;
while (b<=max){
System.out.println(num + " * " + b + " = " + b*num);
b++;
JavaApplication2.main(args);
}
default:
System.out.println(act + " is an Invalid Choice");
}
}
}
}
公共类JavaApplication2{
公共静态void main(字符串[]args)引发IOException
{
System.out.println(“乘法表v1.0”);
System.out.println(“由Roy Jalbout开发”);
System.out.println(“---------------------------”);
System.out.println(“键入“E”退出程序\n键入“H”读取帮助文件\n键入“R”运行程序”);
char act=(char)System.in.read();
开关(act){
案例“e”:
案例“E”:
系统出口(0);
打破
案例“h”:
案例“H”:
System.out.println(“Roy Jalbout开发的乘法表1.0版是一个简单的程序,您所要做的就是选择您想要得到他的乘法表的数字,然后选择该表的最大长度”);
System.out.println(“---------------------------------------------”);
System.out.println(“键入back返回主线程”);
字符串mainthread=scn.next();
如果(“返回”。等于(主线程)){
JavaApplication2.main(args);
打破
案例“r”:
案例“R”:
扫描仪scn=新扫描仪(System.in);
System.out.print(“输入一个数字以得到他的乘法表:”);
int num=scn.nextInt();
System.out.print(“输入乘法表的最大数字:”);
int max=scn.nextInt();
int b=1;
而(b对于我来说,孤立病例的问题是,在我开始切换病例后,有两个未闭合的花括号。
例如,在一个案例中有一个我没有关闭的循环。
一旦我关闭,就没有任何障碍
if ("back".equals(mainthread)){
JavaApplication2.main(args);// you are not closing the brace here..
break;