package com.Summer_0419.cn;
/**
* 猜数字 一共可以猜3次
* 三次都不对则失败 结束游戏
* 猜对一次就成功 结束游戏
* for循环控制游戏次数
*/
import java.util.Scanner;
public class Test_Method05 {
static int a = (int) ((Math.random()*10)+1);
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
guess();
}
private static void guess() {
for (int i = 0; i <= 2; i++) {
System.out.println("请输入一个数字");
int guessNumber = sc.nextInt();
if (guessNumber == a) {
System.out.println("恭喜您获得一个棒棒糖");
break;
}else{
System.out.println("抱歉,您未中奖");
}
}
System.out.println("GameOver");
}
}