I just started programming not too long ago and I am really interested in learning more. Right now, I am in the middle of creating a small "if-else", "while-do" scenario where the user will respond to the questions with the correct integers. I am having trouble though and whenever I hit this part of code:
if (chopperCrash > 100) {
System.out.println("That's not possible!");
System.out.println("Hurry and re-enter a new value before we crash!");
continue;
It continually loops the printed text. Can someone help me on this specific project and also explain to me in detail proper placement of "if-else" and "while-do" statements? Thank you for any help. My apologies if this has already been answered and I am too dense to understand the other previously asked questions. Here is my full block of code:
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;
}
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire