I am trying to write if statements that set conditions that if user input is anything but integers, it will print out a message and exit. I tried == and != string and stuff like that to no avail.
Any help is appreciated Avery
System.out.println("What is the reserve price? ");
int reserve = scanner.nextInt();
System.out.println("What is the bid of Person 1? ");
int p1 = scanner.nextInt();
System.out.println("What is the bid of Person 2? ");
int p2 = scanner.nextInt();
if (p1 < reserve && p2 < reserve){
System.out.println("No one wins because the reserve price of $"+ reserve+ " was not met.");
System.exit(0);
}else if (p1 > p2){
System.out.println("Person 1 wins for $"+p1+".");
}else if (p2 > p1){
System.out.println("Person 2 wins for $"+p2+".");
}
if (p1==p2){
System.out.println("It's a tie at $"+p1+".");
}
Aucun commentaire:
Enregistrer un commentaire