PRoblem Description 統(tǒng)計給定的n個數(shù)中,負(fù)數(shù)、零和正數(shù)的個數(shù)。
Input 輸入數(shù)據(jù)有多組,每組占一行,每行的第一個數(shù)是整數(shù)n(n<100),表示需要統(tǒng)計的數(shù)值的個數(shù),然后是n個實數(shù);如果n=0,則表示輸入結(jié)束,該行不做處理。
Output 對于每組輸入數(shù)據(jù),輸出一行a,b和c,分別表示給定的數(shù)據(jù)中負(fù)數(shù)、零和正數(shù)的個數(shù)。
Sample Input 6 0 1 2 3 -1 0 5 1 2 3 4 0.5 0
import java.util.*;class Main{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); while(n!=0){ int x=0;int y=0;int z=0; for(int i=1;i<=n;i++){ double m = sc.nextDouble(); if(m<0){x=x+1;} if(m==0){y=y+1;} if(m>0){z=z+1;} } System.out.println(x+" "+y+" "+z); break; } } }}新聞熱點
疑難解答
圖片精選