package xu01;
import java.io.*;
public class caishu {
public static void main(String args[])throws IOException{
boolean again=false;
loop1: do {
int trueNum=(int)(Math.random()*9);
System.out.println("游戏开始了");
int i=3;
do {
System.out.println("请输入1-10之间的一个整数,(退出游戏请安");
int guessNum=System.in.read()-48;
System.in.skip(2);
if((guessNum==62)||(guessNum==30))
break loop1;
if(guessNum==trueNum) {
System.out.println("恭喜你中了");
break;
}
else {
if(guessNum>trueNum)
System.out.println("很遗憾偏大了"+guessNum);
else
System.out.println("很遗憾偏小了");
i--;
System.out.println("你还有"+i+"次机会");}
}while(i>0);
if(i==0) {
System.out.println("很遗憾你为猜中,正确数字为"+trueNum+",游戏结束");
}
System.out.println("重新开始按y,结束请安");
char ch=(char)System.in.read();
System.in.skip(2);
if(ch=='Y')again=true;
else if(ch=='N')again=false;
}while(again);
}
}