Java 这个程序给了我一个无限的菜单(DoWhile)
我是新来的。我试图运行一个程序,每当我试图执行它时,它总是给我一个无限的菜单循环。任何帮助都将不胜感激Java 这个程序给了我一个无限的菜单(DoWhile),java,do-while,Java,Do While,我是新来的。我试图运行一个程序,每当我试图执行它时,它总是给我一个无限的菜单循环。任何帮助都将不胜感激 public void show()throws IOException { BufferedReader z=new BufferedReader(new InputStreamReader(System.in)); int ch; input();
public void show()throws IOException
{
BufferedReader z=new BufferedReader(new InputStreamReader(System.in));
int ch;
input();
calculate();
System.out.println(" 1.Print the names of Employees having more than average salary");
System.out.println(" 2.Find the maximum and minimum gross salary ");
System.out.println(" 3.To find the net salaries of employees in ascending order");
System.out.println(" 4.To print the name of employee having the longest name");
System.out.println(" 5.To find the reverse names of the employees");
System.out.println(" 6.To find the reverse of employee's name");
System.out.println(" 7.Exit");
System.out.println("Enter your choice");
ch=Integer.parseInt(z.readLine());
switch(ch)
{
case 1:calc_avg();
break;
case 2:max_and_min();
break;
case 3:sort();
break;
case 4:vowel();
break;
case 5:longest();
break;
case 6:reverse_name();
break;
case 7:
System.out.println("Close");
break;
default:System.out.println("Wrong choice ! ");
}
}
while(ch>=1&&ch<=7);
}
}
这总是给我一个无限循环。如何修复此问题?以下是如何正确修复此问题
public void show()throws IOException {
BufferedReader z=new BufferedReader(new InputStreamReader(System.in));
int ch=0;
input();
calculate();
System.out.println(" 1.Print the names of Employees having more than average salary");
System.out.println(" 2.Find the maximum and minimum gross salary ");
System.out.println(" 3.To find the net salaries of employees in ascending order");
System.out.println(" 4.To print the name of employee having the longest name");
System.out.println(" 5.To find the reverse names of the employees");
System.out.println(" 6.To find the reverse of employee's name");
System.out.println(" 7.Exit");
System.out.println("Enter your choice :");
ch=Integer.parseInt(z.readLine());
while(!(ch>=1&&ch<=7)){
System.out.println("Wrong choice ! Please enter a good choice :");
ch=Integer.parseInt(z.readLine());
}
switch(ch){
case 1:
calc_avg();
break;
case 2:
max_and_min();
break;
case 3:
sort();
break;
case 4:
vowel();
break;
case 5:
longest();
break;
case 6:
reverse_name();
break;
case 7:
System.out.println("Close");
break;
}
}
您的示例不完整,但根据您发布的内容:whilech>=1&&chThanks获得回复。我该如何修复它?你忘记粘贴代码了还是什么…循环从哪里开始??默认语句中断在哪里?欢迎使用堆栈溢出!看起来您需要学习使用调试器。请随便吃点。如果你以后仍然有问题,请随时回来提供更多细节。是的,我粘贴了整个代码,他们说了一些关于格式的事情。我很抱歉我是个笨蛋。但是我已经发布了default或break语句,甚至dowhile循环。我需要粘贴更多的东西吗?检查它以接受好的答案,这样,您就不用客气了;