The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 2 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Write a program in java that reads an unspecified number of integers, finds the largest of them, and counts its occurrences. The reading of input ends when the user enters 0 (zero). Design the program such that it asks the user if they want to continue with new inputs after each set of entries, ending the program only when they do not respond to the question with "yes".
Â
Hint: One way to implement this program is to maintain two integer variables, max (which stores the current maximum number) andcount (which stores its occurrences). Initially, assign the first number to max and 1 to count. Compare each subsequent number withmax. If the number is greater than max, assign it to max and reset count to 1. If the number is equal to max, increment count by 1.
Â
Here is a sample run:
Enter numbers: 3 5 2 5 5 5 0 The largest number is 5 The number of times the largest number occurred is 4 Would you like to continue with new inputs? yes Enter numbers: 10 -5 10 1 2 7 7 7 0 The largest number is 10 The number of times the largest number occurred is 2 Would you like to continue with new inputs? no
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll