计算数字的出现次数

package seven;
import java.util.*;
public class seven_3 {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		 while(input.hasNextLine())//判断是否有输入;
         {
             int [] a = new int[122]; 
             int [] b = new int[122];            
             for(int i=0;;i++){
             a[i] = input.nextInt();
             if(a[i] == 0)
                 break;
              b[a[i]]++;//用来记录a[i]出现的次数;

          }  
          for(int i=0;i<122;i++)
          {
              if(b[i] == 1)
                    System.out.println(i + " occurs "+ b[i] +" time");
              else if(b[i] > 1)
                    System.out.println(i + " occurs "+ b[i] +" times");  
    }

    }
	}

}

猜你喜欢

转载自blog.csdn.net/qq_41404557/article/details/88541545
0条评论
添加一条新回复