计算数字的出现次数

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_41404557/article/details/88541545
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");  
    }

    }
	}

}

展开阅读全文

没有更多推荐了,返回首页