codextj

Untitled

Oct 1st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. import java.util.*;
  2. public class Count2{
  3.     public static void main(String[] args){
  4.  
  5.         Scanner input = new Scanner(System.in);
  6.  
  7.         int number, maxNum=0, count=0, numberCount =0 ;
  8.  
  9.  
  10.         do {
  11.             System.out.print("Enter a number (0 ends the input): ");
  12.             number = input.nextInt();
  13.             numberCount++;
  14.  
  15.             if (number == maxNum){
  16.                 count++;
  17.             }
  18.    
  19.    
  20.             if (number > maxNum){
  21.                 count = 1;
  22.                 maxNum = number;
  23.             }
  24.  
  25.         }
  26.         while (number !=0);
  27.  
  28.         if( number == 0 && numberCount == 1){
  29.  
  30.             System.out.println("No numbers are entered except 0");
  31.             System.exit(0);
  32.         }
  33.         else{
  34.             System.out.println("The maximum number is " +maxNum); // numver --> number
  35.             System.out.println("The count for the max number is " + count);
  36.         }
  37.  
  38.  
  39.     }
  40.  
  41. }
  42. /*
  43.  
  44. Enter a number (0 ends the input): 10
  45. Enter a number (0 ends the input): 9
  46. Enter a number (0 ends the input): 10
  47. Enter a number (0 ends the input): 7
  48. Enter a number (0 ends the input): 11
  49. Enter a number (0 ends the input): 0
  50. The maximum number is 11
  51. The count for the max number is 1
  52.  
  53. Enter a number (0 ends the input): 0
  54. No numbers are entered except 0
  55.  
  56. */
Add Comment
Please, Sign In to add comment