面向对象的第一次pta作业第五题:统计最大数出现次数

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    private static Scanner input;
    public static void main(String[] args) {
        ArrayList<Integer> al=new ArrayList<Integer>();
        int max=0,number,count=0;
        input=new Scanner(System.in);
        do{
            number=input.nextInt();
            al.add(number);
            if(number>max)
                max=number;
        }while(number!=0);
        for(int i=0;i<al.size();i++){
            if(al.get(i)==max)
                count++;

        }
        System.out.println("The largest number is "+max+"\n"+"The occurrence count of the largest number is "+count);

    }
}

 

 达成新成就——在Java里面用数组,但是感觉怪怪的

也不是很能明白 new 的意义

posted on 2020-04-08 20:58  xyx's  阅读(190)  评论(0编辑  收藏  举报

导航