从键盘输入20个整型数据存储一维数组,求正数的个数,用Java语言怎么做?

如题所述

第1个回答  2020-06-16
class Test{
public static void main(String args[]){
int arr[] = new int[20];

for(int i=0; i<20; i++){
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
arr[i] = sc.nextLine();

}

}

int n = 0;

for(int j=0; j<20; j++){
if(arr[j]>0){
n++;

}

}
System.out.println("正数的个数为:"+n);
}

}本回答被网友采纳
相似回答