我是新来的。我试图运行一个程序,每当我尝试执行它时总会给我一个无限的菜单循环。任何帮助将不胜感激。这个程序给我一个无限的菜单(do-while)
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);
}}
这总是给我一个无限循环。我该如何解决 ?
你举的例子是不完整的,但是从您发布的内容:而(CH> = 1个&& H <= 7);导致无限循环 – Sergi
感谢您的答复。我如何解决它 ? – Chirag
你忘了粘贴代码或什么...循环开始?哪里是默认语句中断? – RohitS