计算数字出现的次数 Exercise07_03

 1 import java.util.Scanner;
 2 /**
 3  * @author 冰樱梦
 4  * 时间:2018年下半年
 5  * 题目:计算数字出现的次数
 6  *
 7  */
 8 public class Exercise07_03 {
 9     public static void main(String[] args){
10         int num = 0,temp=0;
11         int[] number=new int[100];
12         int[] su=new int[100];
13         Scanner input=new Scanner(System.in);
14         System.out.println("Enter the integers between 1 and 100: ");
15         for(int i=0;i>=0;i++){
16             temp=input.nextInt();
17             if(temp==0) break;
18             number[i]=temp;
19             su[temp]=temp;
20         }
21         for(int i=0;i<100;i++){
22             for(int j=0;j<100;j++){
23                 if(su[i]!=0){
24                     if(su[i]==number[j]){
25                         num++;
26                     }
27                 }
28             }
29             if(num==1){
30                 System.out.print(su[i]+" occurs "+num+" time\n");
31             }
32             if(num>1){
33                 System.out.print(su[i]+" occurs "+num+" times\n");
34             }
35             num=0;
36         }
37     }
38 }

猜你喜欢

转载自www.cnblogs.com/cherrydream/p/10173868.html