Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program IN JAVA that reads numbers from the keyboard into an array of type int [] . Make sure you are using an

Write a program IN JAVA that reads numbers from the keyboard into an array of type int []. Make sure you are using an array. You may assume that there will be 50 or fewer entries in the array. You program allows any number of numbers to be entered, up to 50. The output is to be a two-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of each element. The list should be sorted on entries in the first column, largest to smallest.

This will require the use of TWO one-dimensioned arrays or ONE two-dimensioned array. **PLEASE SPECIFY WHICH ONE YOU USE IN COMMENTS**

*The problem says that there will be 50 or fewer numbers entered. Therefore, the array size will be exactly 50. As numbers are entered, your program will terminate input if the user tries to enter more than 50 numbers or whenever the user enters the terminating value (-999). Ex: For the array

-12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12

The output should be

N Count

4 2

3 3

2 3

1 4

-1 1

-12 4

Program OUTLINE:

Program Logic (algorithm):

- Perform any initializations

- Loop through the users inputs ( max of 50 or terminating value of -999 )

o Prompt the user for their input

o Read the users entry.

If the value is -999, exit the loop

o Determine if the users entry has been entered before

o If it is a new value, add to the Numbers array and set the entry in the Count array to 1.

o If the number has been entered previously, increment the Count array entry by one.

- Once the loop terminates:

o Print the Numbers array and the corresponding Count array

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

=+1 Why are local employment laws important to IHRM?

Answered: 1 week ago

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago