This is not the original code that I'm having problems with because that code is tied to other classes, but the code i'm working with is similar and giving me a similar problem. I can't for the life of me figure out why none of my if statements are running when I put them inside a while loop. Any help is greatly appreciated.
import java.util.Scanner;
public class deleteme {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int input;
System.out.print("enter something");
input = scan.nextInt();
scan.nextLine();
while(input != 3)
{
if (input == 1)
{
System.out.print("done");
}
else if (input == 2)
{
System.out.print("hi");
}
}
}
}
I'm attempting to have a loop that asks the user to choose an option, follows through with that option, asks again, and that doesn't terminate until an escape command is input, in this case the number 3
Aucun commentaire:
Enregistrer un commentaire