package com.oned4z;
import java.util.Scanner;
/**
* @program: com.oned4z
* @description: 猜数游戏
* @author: Mr.Lin
* @create: 2019年7月4日
**/
public class One01 {
static Scanner sc= new Scanner(System.in);
public static void main(String[] args) {
int[] nums = new int[]{8,4,2,1,23,344,12};
int sum = 0;
boolean boo = false;
System.out.println("这是猜数游戏,请猜数:");
int guess = sc.nextInt();
for (int num : nums) {
if (num == guess){
boo = true;
}
}
System.out.println("数组元素分别是:");
for (int num : nums) {
sum += num;
System.out.print(num+" ");
}
System.out.println("
数列中所有值的和为: "+sum);
if (boo){
System.out.println("真棒,猜对了 "+guess);
}else {
System.out.println("猜错了,再接再厉 "+guess);
}
}
}