hello,今天给大家实现猜数升级版的小游戏,看看大家能不能看出我实现了哪些功能?🕵️♂️🕵️♂️🕵️♂️🕵️♂️🕵️♂️
package com.Cx_330.array;
import java.util.Random;
import java.util.Scanner;
public class ArrayPlay {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
int[] arr=new int[5];
for (int i = 0; i < arr.length; i++) {
arr[i]=random.nextInt(20)+1;
}
int count=0;
while (count<5){
System.out.println("请猜第"+(count+1)+"的幸运数字: ");
int lucky=scanner.nextInt();
if(lucky==arr[count]){
System.out.println("恭喜你猜中第"+(count+1)+"个幸运数字: "+arr[count]);
count++;
continue;
}
if(lucky<arr[count]){
System.out.println("猜小了!");
}else {
System.out.println("猜大了");
}
}
System.out.println("恭喜你猜中五个幸运数字!");
}
}