2016-09-13 8 views
0

私はちょうどあまりにもずっと前にプログラミングを始めたばかりで、もっと学習することに本当に興味があります。今、私は、ユーザーが正しい整数で質問に回答する小さな「if-else」、「do-do」シナリオを作成する途中です。私は問題を抱えていますが、コードのこの部分にヒットしたときはいつでも:While-Doステートメントを適切に配置する場所

if (chopperCrash > 100) { 


     System.out.println("That's not possible!"); 

     System.out.println("Hurry and re-enter a new value before we crash!"); 
     continue; 

印刷されたテキストが繰り返しループします。誰かがこの特定のプロジェクトで私を助け、「if-else」と「while-do」のステートメントの適切な配置について私に説明することはできますか?何か助けてくれてありがとう。これが既に答えられている場合、私は謝罪し、以前に尋ねられた他の質問を理解するにはあまりにも密度が高い。ここでは、コードの私の完全なブロックがある:

import java.util.Scanner; 

public class FirstClass { 
public static void main (String[] args){ 

    System.out.println("The chopper is going down because your lack of experience."); 

    System.out.println("How much throttle are you going to give it?"); 

    System.out.println("(enter a number between 1 and 100)"); 

    Scanner FirstScan = new Scanner(System.in); 


    int number = FirstScan.nextInt(); 
    int chopperCrash = number; 

    while (true){  

    if (chopperCrash >= 60 && chopperCrash <= 100){ 

     System.out.println("Looks like we'll make it another day!"); 
     break; 
    } 

     else{  

    if (chopperCrash > 100) { 


     System.out.println("That's not possible!"); 

     System.out.println("Hurry and re-enter a new value before we crash!"); 
     continue; 
    } 
    else{ 
    if (chopperCrash <= 59) { 
     System.out.println("Not enough throttle!"); 
     System.out.println("We're going down!"); 

     break; 
      } 
      } 
     } 
     } 
    } 
} 

答えて

1

あなたはループの外に入力コードを左:

int number = FirstScan.nextInt(); 
int chopperCrash = number; 

while (true) { 

を使用すると、ループ内を割り当てることはありませんので、それは永遠に続きます。それで、そのように内部に入れてください:

while (true) { 
    int number = FirstScan.nextInt(); 
    int chopperCrash = number; 
関連する問題