Java程序计算正数,零和负数
时间:2020-02-23 14:35:07 来源:igfitidea点击:
在本教程中,我们将看到Java程序来计算正数,零和负数
import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
int contp=0, cntn=0, cntz=0, i;
int arr[] = new int[10];
Scanner scan = new Scanner(System.in);
System.out.print("Enter 10 Numbers : ");
for(i=0; i<10; i++){
arr[i] = scan.nextInt();
}
for(i=0; i<10; i++){
if(arr[i] < 0){
cntn++;
}else if(arr[i] == 0){
cntz++;
}else{
contp++;
}
}
System.out.print(contp + " Positive Numbers");
System.out.print("\n" + cntn + " Negative Numbers");
System.out.print("\n" + cntz + " Zero");
}
}
输出:
Enter 10 Numbers : 10 0 45 -10 67 0 76 -33 64 -92 5 Positive Numbers 3 Negative Numbers 2 Zero

