package test;
import java.util.Scanner;
public class 猜数字游戏 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你猜的数");
int i = (int )((Math.random()*100)+1);
int count = 5;
while(true){
int value = sc.nextInt();
count --;
System.out.println("你还有"+count+"次机会");
if( count == 0 ){
System.out.println("你猜了五次啦,GAME OVER!");
break;
}else if( i > value ){
System.out.println("你猜小了");
}else if( i < value ){
System.out.println("你猜大了");
}else {
System.out.println("你猜对啦!恭喜你!!!");
}
}
}
} |