public class caishuziyouxi { public static void main(String[] args) { int data[] = new int[5]; Random r = new Random(); for (int i = 0; i < data.length; i++) { data[i] = r.nextInt(20)+1; } Scanner sc = new Scanner(System.in); OUT: while(true){ System.out.println("请输入1-20之间的整数进行猜测:"); int guessData = sc.nextInt(); for (int i = 0; i < data.length; i++) { if(data[i] ==guessData){ System.out.println("猜中"+i); break OUT; } } System.out.println("错误"); } for (int i = 0; i < data.length; i++) { System.out.println(data[i]+"\t"); } } }
java实现猜数字游戏
最新推荐文章于 2024-11-05 19:36:08 发布