package str; import java.util.Random; import java.util.Scanner; public class demo10 { public static void main(String[] args) { Random r=new Random(); int num=r.nextInt(100)+1; Scanner sc=new Scanner(System.in); while(true){ System.out.println("请输入数:"); int a=sc.nextInt(); if(a==num){ System.out.println("猜对了!"); break; } if(a<num){ System.out.println("猜小了,请继续:"); } if (a>num){ System.out.println("猜大了,请继续:"); } } System.out.println("游戏结束"); } }
Java 猜数字小游戏
最新推荐文章于 2024-08-16 23:08:28 发布