HDU 2008 JAVA

来源:互联网 发布:linux各个目录的作用 编辑:程序博客网 时间:2024/06/06 20:12

Problem Description
统计给定的n个数中,负数、零和正数的个数。

Input
输入数据有多组,每组占一行,每行的第一个数是整数n(n<100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。

Output
对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。

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;      }    }  }}
0 0
原创粉丝点击