class SwitchTest
{
public static void main(String args[])
{
try{
char a;
System.out.println("choose a number 1-3:");
a = (char)System.in.read();
switch(a)
{
case '0' :
System.out.println("no character enter");
break;
case '1' :
System.out.println("\nenter 1");
break;
case '2':
System.out.println("enter 2");
break;
case '3':
System.out.println("enter 3");
break;
default:
System.out.println("enter error");
}
}catch(Exception e){
System.out.println("Error"+e.getMessage());
}
}
}
★★ 签名 ★
================================================================
是的!就是我!
史上最负盛名的黑猫,现在不做警长了,郁闷的趴在屋顶上看MM。
{
public static void main(String args[])
{
try{
char a;
System.out.println("choose a number 1-3:");
a = (char)System.in.read();
switch(a)
{
case '0' :
System.out.println("no character enter");
break;
case '1' :
System.out.println("\nenter 1");
break;
case '2':
System.out.println("enter 2");
break;
case '3':
System.out.println("enter 3");
break;
default:
System.out.println("enter error");
}
}catch(Exception e){
System.out.println("Error"+e.getMessage());
}
}
}
★★ 签名 ★
================================================================
是的!就是我!
史上最负盛名的黑猫,现在不做警长了,郁闷的趴在屋顶上看MM。
{
public static void main(String args[])
{
char a;
System.out.println("choose a number 1-3:");
try{
a = (char)System.in.read();
switch(a)
{
case '\r':
System.out.println("no character enter");
break;
case '1' :
System.out.println("\nenter 1");
break;
case '2':
System.out.println("enter 2");
break;
case '3':
System.out.println("enter 3");
break;
default:
System.out.println("enter error");
}
}catch(Exception e){System.out.println(e);}
}
}
修改如下char t;
System.out.println("choose a number 1-3:");
t = (char)System.in.read();
int a=Integer.parseInt(t);
switch(a)
......case语句中将字符 '1','2'...换为数字 1,2
不过绝对不能再看那本书了。csdn上的朋友给我太多了,谢谢了。