package day_05; import java.util.Scanner; public class Demo_02 { public static void main(String[] args) { int num=(int)((Math.random()*100)+1); int i=1,a=0; while(a!=num) { System.out.println("请猜一个随机数(1-100):"); Scanner sc=new Scanner(System.in); a=sc.nextInt(); if(i<=3) { if(a>num) { System.out.println("猜大了,请重新猜!"); }else if(a<num) { System.out.println("猜小了,请重新猜!"); }else { System.out.println("恭喜你,猜对了!!!"); } }else { System.out.println("抱歉,你猜的次数过多..."); } i++; } } }