package ch06; import java.util.Scanner; /** * Created by liwenj on 2017/7/18. */ public class test11 { public static void main(String[] args) { int[] a = {1, 2, 3, 4, 5, 6, 7}; int sum = 0; //输出没一个数字 for (int i = 0; i < a.length; i++) { System.out.println(" " + a[i]); } //求和 for (int i = 0; i < a.length; i++) { sum = sum + a[i]; } System.out.println("和是" + sum); //输入一个数字判断数组里面有没有这个数 Scanner input = new Scanner(System.in); boolean s = false; System.out.println("输入一个数字:"); int num = input.nextInt(); for (int i = 0; i < a.length; i++) { if (num == a[i]) { s=true; System.out.println("有这个数字,这个数是:" + a[i]); break; } } if(s==false){ System.out.println("没有要查找的元素"); } } }