I have this code which is a minigame, you type a number and if is divisible by 5 you get a "Fizz" / if divisible by 3 you get a "Buzz" / and if divisible by both, you get a "FizzBuzz".
Now, i need help to end the "while(true)" loop, peacefully with a mesage like... "goodbye" whenever you enter the letter "X".
I would apreciate if you can add the aswer to the full code and a little explain of the code.
public class CLass {
public static void main(String[] args) {
int number;
Scanner scan = new Scanner(System.in);
while (true) {
System.out.print("number: ");
number = scan.nextInt();
if (number % 5 == 0 && number % 3 == 0)
System.out.println("FizzBuzz");
else if (number % 5 == 0)
System.out.println("Fizz");
else if (number % 3 == 0)
System.out.println("Buzz");
else
System.out.println(number);
}
}
}