Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Count2{
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- int number, maxNum=0, count=0, numberCount =0 ;
- do {
- System.out.print("Enter a number (0 ends the input): ");
- number = input.nextInt();
- numberCount++;
- if (number == maxNum){
- count++;
- }
- if (number > maxNum){
- count = 1;
- maxNum = number;
- }
- }
- while (number !=0);
- if( number == 0 && numberCount == 1){
- System.out.println("No numbers are entered except 0");
- System.exit(0);
- }
- else{
- System.out.println("The maximum number is " +maxNum); // numver --> number
- System.out.println("The count for the max number is " + count);
- }
- }
- }
- /*
- Enter a number (0 ends the input): 10
- Enter a number (0 ends the input): 9
- Enter a number (0 ends the input): 10
- Enter a number (0 ends the input): 7
- Enter a number (0 ends the input): 11
- Enter a number (0 ends the input): 0
- The maximum number is 11
- The count for the max number is 1
- Enter a number (0 ends the input): 0
- No numbers are entered except 0
- */
Add Comment
Please, Sign In to add comment