Laboratory Manual ITE4
Laboratory Manual ITE4
Problem:
Create a program that takes ten numbers, shows how many distinct numbers there are, and
arranges the numbers in the order they were entered, with exactly one space between each
number (such that if a number appears more than once, it is shown only once). (Hint: If a
number is new, read it and store it to an array; if it's already in the array, disregard it.) The array
then contains the different numbers.
Solution:
Step 1: Understand the Problem
You need to input 10 numbers from the user.
You must store only distinct numbers in an array.
After input, display:
Count of distinct numbers
The distinct numbers in input order (duplicates should not be stored).
Sample Run:
Enter 10 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
[email protected] www.nwssu.edu.ph
Program Title: Eliminate duplicates
Problem:
Write a method that returns a new array by eliminating the duplicate values in the array using
the following method header:
public static int[] eliminateDuplicates(int[] list)
Write a test program that reads in 10 integers, invokes the method, and displays the distinct
numbers separated by exactly one space.
Solution:
Step 1: Understand the Problem
We need to read 10 numbers from the user.
We must create a method eliminateDuplicates(int[] list) that:
Takes an integer array as input.
Returns a new array with only distinct values (preserving input order).
The main program should:
Call eliminateDuplicates().
Display the distinct numbers.
Sample Run:
Enter 10 numbers: 1 2 3 2 1 6 3 4 5 2
The distinct numbers are: 1 2 3 6 4 5
[email protected] www.nwssu.edu.ph