public static void main(String[] args) {
int [] array1 = {8,4,2,1,23,344,12};
int sum = 0;
for (int i = 0; i < array1.length; i ++){
System.out.println(array1[i] + "\t");
sum += array1[i];
}
System.out.println("和为:" + sum);
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你要猜的数据:");
int caishu = scanner.nextInt();
boolean flag = true;
for (int i = 0; i <array1.length; i ++){
if (caishu == array1[i]){
flag = false;
System.out.println("恭喜你猜中了");
break;
}
}
if (flag) {
System.out.println("你猜的数字在数组中不存在");
}
}