版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LoveRong521/article/details/81485152
/*
猜数游戏:从键盘中任意输入一个数据,判断数列中是否包含此数;
*/
import java.util.Scanner;
public class Test12{
public static void main(String[] args){
int[] nums = {30,17,6,2,44,35};
Scanner input = new Scanner(System.in);
System.out.println("请输入你要猜的数:(50以内)");
int userNum = input.nextInt();
boolean flag = false;
for(int x:nums){
if(userNum==x){
flag = true;
break;
}
}
if(flag){
System.out.println("恭喜你,猜对了");
}else{
System.out.println("恭喜你,猜错了");
}
}
}