(Print distinct numbers) Write a program that reads in 10 numbers and displays the number of distinct numbers and the distinct numbers in their input order and separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers.
this is what i have so far
public class Exercise07_05 {
public static void main(String[] args) {
// numbers array will store distinct values, maximum is 10
int[] numbers = new int[10];
// How many distinct numbers are in the array
int numberOfDistinctValues = 0;
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter ten numbers: ");
for (int i = 0; i < numbers.length; i++) {
// Read an input
int value = input.nextInt();
boolean isinthearray = false;
for(int j=0; j < numberofdistinctvalue; j++) {
if (value == number[j]) {
isinthearray = true;
}
}
if(!isinthearray){
number[numberofdistinctcalues] =value;
numberofdistinctvalues++;
}
}
System.out.println("The number of distinct numbers is " + count);
System.out.print("The distinct numbers are");
for (int i = 0; i < distinctNumbers.length; i++) {
if (distinctNumbers[i] > 0)
System.out.print(" " + distinctNumbers[i]);
}
System.out.println();
}
![**7.5 (Print distinct numbers)**
Write a program that reads in 10 numbers and displays the number of distinct numbers and the distinct numbers in their input order and separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers.
---
**Sample Run for Exercise07_05.java**
Enter input data for the program (Sample data provided below. You may modify it.):
`1 2 3 2 1 6 3 4 5 2`
Buttons:
- **Show the Sample Output Using the Preceding Input**
- **Reset**
**Execution Result:**
```
JDK8>java Exercise07_05
Enter ten numbers: 1 2 3 2 1 6 3 4 5 2
The number of distinct numbers is 6
The distinct numbers are 1 2 3 6 4 5
JDK8>
```
Explanation: The program receives a series of ten numbers and processes them to determine and display the distinct numbers and the count of these distinct numbers. In the sample execution, the input numbers result in six distinct numbers being printed.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fefb9f528-028f-4252-997c-2f81dfab4c7c%2Fd1f9aa17-cc1b-445f-a4ba-aa1cd5101578%2F1ucpr3_processed.png&w=3840&q=75)
![### Suggested Template
```java
public class Exercise07_05 {
public static void main(String[] args) {
// numbers array will store distinct values, maximum is 10
int[] numbers = new int[10];
// How many distinct numbers are in the array
int numberOfDistinctValues = 0;
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter ten numbers: ");
for (int i = 0; i < numbers.length; i++) {
// Read an input
int value = input.nextInt();
Step 1: Check if value is in numbers
Step 2: If value is not in numbers, add it into numbers
Step 3: Increment numberOfDistinctValues
}
Step 4: Display output
}
}
```
### Explanation
This Java program template is designed to prompt the user to enter ten numbers and then determine how many distinct numbers were entered.
1. **Array Declaration**: An integer array `numbers` is created to store up to 10 distinct values.
2. **Initialization**: The variable `numberOfDistinctValues` is used to track the count of distinct numbers entered by the user.
3. **User Input**: A `Scanner` object is used to read user input from the console.
4. **Logic**:
- The program prompts the user to input ten numbers.
- For each input, the code checks if the number is already in the `numbers` array.
- If it is not present, the number is added to the array.
- The counter `numberOfDistinctValues` is incremented each time a new number is added.
5. **Output**: The distinct values and their count are displayed (implementation of Step 4 is required).
Note: The sections marked as "Step" require complete implementation logic to function as expected.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fefb9f528-028f-4252-997c-2f81dfab4c7c%2Fd1f9aa17-cc1b-445f-a4ba-aa1cd5101578%2Fhi5o92g_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)