please note that I can only use loops
I need to code a program which prompts the user to input integers. When the user enters three unique integers, the program should stop and display the unique integers.
Example
Enter a integer:
1
Enter a integer:
1
Enter a integer:
2
Enter a integer:
1
Enter a integer:
3
First 3 unique numbers entered are: 1 2 3
I need help in figuring out how I can search the recently input value to the previous values and discard them if they are the same (duplicates) using for loops
Code java:import java.util.Scanner; public class uniqueinteger { public static void main(String[] args) { int userInput, array[]; int i = 0; array = new int[3]; Scanner myScan = new Scanner (System.in); while (i <= 3){ System.out.println("Enter a non negative integer: "); userInput = myScan.nextInt(); array[i] = userInput; i++; if (userInput < 0) i--; } System.out.println("First 3 unique numbers entered are: " + array[i] + " "); } }
