0
How to use user input(scanner) in switch?
3 Respostas
+ 3
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Choose any number from 0-3");
int x = sc.nextInt();
switch(x){
case 0:
System.out.println("Zero");
break;
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;
case 3:
System.out.println("Three");
break;
default:
System.out.println("You put something else, didn't you...");
}
}
}
//I hope that helps
+ 1
Thanks exactly what I was looking for :D by the way I just finished my program with the Scanner problem. Thanks a lot :)
+ 1
Thanks Earl