s3a
September 13th, 2009, 05:12 PM
I do not need the last break; statement right? Anyways, my real question is: how do I modify the following code to take an input that is letters instead of numbers?
import java.util.Scanner;
public class test2
{
public static void main (String [] args)
{
Scanner kb;
kb = new Scanner(System.in);
int x = kb.nextInt();
switch(x)
{
case 1:
System.out.print("One"); break;
case 2:
System.out.print("Two"); break;
case 3:
System.out.print("Three"); break;
default:
System.out.print("Not 1,2 or 3"); break;
}
}
Any input would be greatly appreciated!
Thanks in advance!
import java.util.Scanner;
public class test2
{
public static void main (String [] args)
{
Scanner kb;
kb = new Scanner(System.in);
int x = kb.nextInt();
switch(x)
{
case 1:
System.out.print("One"); break;
case 2:
System.out.print("Two"); break;
case 3:
System.out.print("Three"); break;
default:
System.out.print("Not 1,2 or 3"); break;
}
}
Any input would be greatly appreciated!
Thanks in advance!