文档库 最新最全的文档下载
当前位置:文档库 › JAVA中的Switch应用方法

JAVA中的Switch应用方法


package Day1;

import java.util.Scanner;

public class Lesson1 {
public static void main(String[] args){
Scanner in =new Scanner(System.in);//创建一个输出
int a = in.nextInt();//写入一个数字
int b = (int)(Math.random()*9);//生成一个0~9的数字
/*
if(b>9){
System.out.println(b);
} else {
System.out.println("失败");
}
System.out.println(b);
*/

String c = "!";
String d = "!";
switch(a){
case 1:
c = "抱歉";
break;
case 2 :
c ="抱歉";
break;
case 4 :
c ="意外";
break;
case 5 :
c ="意外";
break;
case 6 :
c ="意外";
break;
case 7 :
c ="刚好";
break;
case 8 :
c ="太多了";
break;
case 9 :
c ="太大";
break;


}
switch(b){
case 1:
d ="0";
break;
case 2 :
d = "0";
break;
case 4:
d = "0";
break;
case 5:
d = "0";
break;
case 6:
d = "0";
break;
case 7:
d = "刚好";
break;
case 8:
d = "0";
break;
case 9:
d = "0";
break;
}
if(a==b){
System.out.println("恭喜成功了"+"b="+b+"!!!!");
}else{
if(a>b){
System.out.println("抱歉"+b);
}else{
System.out.println("抱歉太小了"+b);
}
}

}
}

相关文档