JAVA小程序(0级)-- 猜拳

一个简单的采取按游戏

选择要出的选项前的数字(1.剪刀,2.石头,3.布)回车,即判断输赢

package ;

import java.util.Scanner;

public class Guess {

	public static void main(String[] args) {
		Scanner a=new Scanner(System.in);
		System.out.println("-----猜拳游戏-----");
		System.out.println("请输入你要出的");
		System.out.println("1.剪刀,2.石头,3.布");
		int person=a.nextInt();
		int computer=(int)(Math.random()*3+1);
		String  choose="剪刀";
		switch(person){
		case 1:
			choose="剪刀";
			break;
		case 2:
			choose="石头";
			break;
		case 3:
			choose="布";
			break;
		}
		String com="剪刀";
		if(computer==1){
			com="剪刀";
		}
		if(computer==2){
			com="石头";
		}
		if(computer==3){
			com="布";
		}
		System.out.println("你出的是"+choose);
		System.out.println("电脑出的是"+com);
		if(computer==person){
			System.out.println("平局");
		}else {
				if(computer==1&&person==3||computer==2&&person==1||computer==3&&person==2){
				System.out.println("你输了");			
		}else{
			System.out.println("你赢了");
		}
		}
	}

}
经验分享 程序员 微信小程序 职场和发展