Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[IN JAVA PLEASE] Write a program that reads in non-negative integers and stores and displays distinct numbers (i.e., if a number appears multiple times, it

[IN JAVA PLEASE]

Write a program that reads in non-negative integers and stores and displays distinct numbers (i.e., if a number appears multiple times, it is stored and displayed only once). Your program should allow up to 1000 distinct numbers to be stored and displayed. Use the following algorithm (this is required!): Read each number and store it in an array if it is new. If the number is already in the array, don't add it to the array. The user will indicate that they are done entering numbers by entering a negative number. Here is a sample run:

Enter a non-negative integer (negative to quit): 1 Enter a non-negative integer (negative to quit): 2 Enter a non-negative integer (negative to quit): 3 Enter a non-negative integer (negative to quit): 2 Enter a non-negative integer (negative to quit): 1 Enter a non-negative integer (negative to quit): 6 Enter a non-negative integer (negative to quit): 3 Enter a non-negative integer (negative to quit): 4 Enter a non-negative integer (negative to quit): 5 Enter a non-negative integer (negative to quit): 2 Enter a non-negative integer (negative to quit): -4 You entered: 1 2 3 6 4 5 

To get credit for this assignment you must use appropriate decomposition! You should have a method to read the numbers and a method to print the resulting array. The method that reads the numbers should call an additional method that returns a bool value indicating whether a number is already in the array. At the conclusion of the call to the method that reads the numbers, the array MUST contain only distinct numbers.

Additionally, you must not sort the array. The numbers must appear in the same order in which they were typed.

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

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

Question What is an educational benefit trust and how is it used?

Answered: 1 week ago

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago