publicclassTest{publicstaticvoidmain(String[] args){//产生随机数0-99int x =(int)(Math.random()*100);//ScannerScanner player =newScanner;
//用户提示:System.out.println("请输入猜测的数字:");//几次机会就循环几次,猜对就退出,停止运行for(int i =0;i<10;i++){int y = player.nextInt();if(y<x){System.out.println("猜小了!!!");}elseif(y>x){System.out.println("猜大了!!!");}else{System.out.println("猜对了~ ~ ~");return;//返回猜对就结束循环}
plaryer.close();//用户输入结束Scanner}}}