打印一组数字中最大数及出现的次数

来源:互联网 发布:软件小品官网 编辑:程序博客网 时间:2024/05/16 16:23
/*Enter the integer numbers: 3 5 2 5 5 5 0The largest number is: 5The occurence count of the largest number is:4*/import java.util.Scanner;public class ShowMaxNumberAndCount {  public static void main(String[] args) {    Scanner input = new Scanner(System.in);    int number = 1, max, count = 1;    System.out.print("Enter the integer numbers: ");    max = input.nextInt();    while (number != 0) {      number = input.nextInt();      if (max < number)        max = number;      else if(max == number)          count++;    }    System.out.println("The largest number is: " + max);    System.out.println("The occurence count of the largest number is:" + count);  }}
0 0
原创粉丝点击