(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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
Show the Sample Output Using the Preceeding Input
Reset
Execution Result:
JDK8>java Exercise07_05
Enter ten numbers: 1 2 3 21 6 3 4 5 2
The number of distinct numbers is 6
The distinct numbers are 1 2 3 6 4 5
JDK8>
Transcribed Image Text:**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 Show the Sample Output Using the Preceeding Input Reset Execution Result: JDK8>java Exercise07_05 Enter ten numbers: 1 2 3 21 6 3 4 5 2 The number of distinct numbers is 6 The distinct numbers are 1 2 3 6 4 5 JDK8>
Suggested template
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
Transcribed Image Text:Suggested template 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education