write a java program that inputs 5 numbers, each between 10 and 100 inclusive. as each number is read display it only if it's not a duplicate of any number already read. display the set of unique values input after the user enters each new value.
Answers
Answer:
Java bava bajava ok bro lxkxlx
Answer:
How to get the unique values:
The distinct() function is an intermediate action that filters the stream before passing it on to the following process. The Java Stream collect() method in Java is used to collect stream elements into a collection (in this case a list). The return type is Stream, which is both an interface and a function.
Explanation:
Enter an integer between and :The complete set of unique values entered is:
Unique Value is
Unique Value : is
Unique Value : is
import java.util.ArrayList;
import java.util.Scanner;
public class DuplicateElimination {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList list = new ArrayList();
int num;
for (int i = 0; i < 5; ++i) {
System.out.print("Enter an integer between 10 and 100:");
num = in.nextInt();
if (!list.contains(num)) {
list.add(num);
System.out.println("This is the first time " + num + " has been entered");
}
}
for (int i = 0; i < list.size(); ++i) {
System.out.println("Unique Value " + (i+1) + " is " + list.get(i));
}
}
}