1 import java.util.Scanner; 2 import java.util.Random; 3 public class mulTip{ 4 public static void main(String[] args){ 5 System.out.println("请输入0-100的整数"); 6 Scanner sc = new Scanner(System.in); 7 Random ac = new Random(); 8 int guess = ac.nextInt(100)+1; 9 for(int i=1;i<=100;i++){ 10 int key = sc.nextInt(); 11 if(key==guess){ 12 System.out.println("恭喜您 答对了"); 13 break; 14 }else if(key>guess){ 15 System.out.println("您猜的数字大了"); 16 }else{ 17 System.out.println("您猜的数字小了"); 18 19 } 20 System.out.println("您还有"+(5-i)+"次机会"); 21 if(i==5){ 22 System.out.println("很遗憾 你没机会了 正确的数字为"+guess); 23 break; 24 } 25 } 26 } 27 }