I just started with Java 3 days ago and I need help with a if statement. What I want to do is after the default, put an if statement that basically says if namee equals Mike or lady print out "Type a number between 1-3 to see your prize''. And if you type for example 1, it should print out ''you won a Bicycle''.
I know that not that many Pro-programmers use ''switch'' but that's all I know for now :)
Thank you!
import java.util.Scanner; public class Ifwasif {
public static void main (String [] args) {
System.out.println("Welcome to our Store!");
System.out.println("we hope you will find what you're looking for");
Scanner input = new Scanner (System.in);
System.out.print("To check out, please type your name: ");
String name = input.nextLine();
System.out.print("You need to confirm your age, please type your age: ");
int age = input.nextInt();
Scanner input1 = new Scanner (System.in);
System.out.print("You have an award to collect! To collect it type your name: ");
String namee = input1.nextLine();
switch (namee) {
case ("Mike"):
System.out.println("Congrats, you are the Winner!");
break;
case ("Don"):
System.out.println("Sorry you are not the winner!Better luck next time");
break;
case ("lady"):
System.out.println("Congrats, you are the Winner!");
break;
default:
System.out.println("Your name is not in the list!");
}
}
}
Aucun commentaire:
Enregistrer un commentaire