Guess1

这次没有用递归了,上班没时间学 学JAVA 学的好慢。下午又空又改进了下  用递归太麻烦了。
import java.util.Scanner;
public class Guess1 
{
	static int x; //对比操作判断,归零for循环初始值
	static int j; //for 循环
	static 	Guess1 rm = new Guess1();
	public void exit() //退出
	{
		System.exit(0); 
	}
	public void reminder() //提示
	{
		System.out.println("---------------------");
		System.out.println("**请输入有效数字1-3**");
		System.out.println("**1剪刀;2石头;3布**");
		System.out.println("---------------------");
	}
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		try
		{
			while(true)
			{
				for(j = 0; j < 3; ++j)
				{
					System.out.println("猜拳游戏");
					System.out.println("1为拳头2为剪刀3为布");
					System.out.println("您还有"+(3-j)+"次游戏机会");
					int personInputValue = in.nextInt();
					if(personInputValue < 4 )
					{
						int inputValue = (int)(Math.random()*3)+1;
						String Marks = "拳头";
						String Marks2 = "拳头";
						switch(personInputValue)
						{
						case 1:
							Marks = "剪刀";
							break;
						case 2:
							Marks = "石头";
							break;
						case 3:
						    Marks = "布";
						    break;
						}
						switch(inputValue)
						{
						case 1:
							Marks2 = "剪刀";
							break;
						case 2:
							Marks2 = "石头";
						case 3:
							Marks2 = "布";
						}
						while(x < 3)
						{
							if(personInputValue == inputValue)
							{
								System.out.println("平局"+Marks2+"and"+Marks);
								break;
							}
							else if(personInputValue == 1 && inputValue == 2 || personInputValue == 2 && inputValue == 3 ||personInputValue == 3 && inputValue == 1 )
							{
								System.out.println("您输了"+Marks2+"and"+Marks);
								break;
							}
							else
							{
								System.out.println("您赢了"+Marks2+"and"+Marks);
								break;
							}
						}
					}
					else
					{
						rm.reminder(); //调用提示信息
					}
				}
				System.out.println("继续请输入yes,退出任意输入");
				String flag = in.next();
				if(flag.equals("yes"))
				{
					j = x;
				}
				else
				{
					System.out.println("游戏结束");
					rm.exit(); //调用程序退出
				}
			}
		}
		finally
		{
			in.close();
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值