第三天 switch

作者在 2017-07-11 00:09:56 发布以下内容
package example;//switch random Scanner
//主题:猜拳游戏(基于随机数)
import java.util.Scanner;


public class switch2 {


public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("please input a number:");
int m = s.nextInt();
int n = (int)(Math.random()*3)+1;

String a,b;
switch(m){
case 1: a="剪刀";break;
case 2: a="石头";break;
case 3:a="bu";break;
default:a="error";


}
switch(n){
case 1: b="剪刀";break;
case 2:b="石头";break;
case 3:b="bu";break;
default : b = "error";

}
if(a=="error"||b=="error"){System.out.println("error");}
else if(m==n){System.out.println("your num is:"+a+",computer num is:"+b+"pingju");
}
else if(m==1&&n==2||m==2&&n==3||m==3&&n==1){
System.out.println("your num is:"+a+",computer num is:"+b+"you lose!what a pity!");
}
else System.out.println("you win");
}
}
//Random xx= new Random();
//int a = xx.nextInt(10);
//System.out.println(a);
//Double a = Math.random()*10;
//System.out.println(a);
//System.out.println((int)(Math.random()*10));


java 笔记 | 阅读 541 次
文章评论,共0条
游客请输入验证码
文章归档