package com.java.demo_2;
import java.util.Arrays;
import java.util.Scanner;
public class numbers {
/**
* 输入10个数字,用数组接收这10个数字,并求出所有正数的和; 当用户输入非数字时退出; 数字由控制台输入
*/
public static void main(String[] args) {
String result = "";
int sum = 0 ;
int[] numbers = new int[10];
Scanner input = new Scanner(System.in);
for (int i = 1; i <= 10; i++) {
System.out.print("请输入第" + i + "个数:");
//如何在此处添加输入的为数字??
numbers[i - 1] = input.nextInt();
if (numbers[i - 1] >= 0) {
result += numbers[i - 1] + ", ";
sum += numbers[i - 1];
}
}
System.out.println();
System.out.println("************************");
System.out.println("查看数组中的值:");
System.out.println(Arrays.toString(numbers));
System.out.println("************************");
System.out.println("[正数是:]" + result);
System.out.println("[正数和为:]" + sum);
}
}