2016-12-04 3 views
-3

私はここがきっかけです。私はいつでも私はそれを実行しようとすると無限のメニューループを与えるプログラムを実行しようとしています。どんな助けでも大歓迎です。このプログラムは私に無限のメニューを与えます(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); 

}}

これはいつも私に無限ループを提供します。どのように私はこれを修正するのですか?ここで

+0

あなたの例では、完全ではありませんが、あなたが投稿したものとは:(CH> = 1 && CH <= 7)ながら、無限ループを引き起こします – Sergi

+0

返信いただきありがとうございます。どのように私はそれを修正するのですか? – Chirag

+0

コードを貼り付けるのを忘れてしまった、または何を...ループが始まっていますか?デフォルトのステートメントブレークはどこですか? – RohitS

答えて

0

が適切に行う方法である。)

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; 
     } 
    } 
+0

ありがとうございます。 – Chirag

+0

「良い答えとして受け入れる」にチェックしてください。 – azro

関連する問題