I'm working on a problem where I need to use a one-dimensional array to write an application that inputs five numbers, each between 10 and 100, inclusive. As each number is read, it displays it only if it is not a duplicate of a number already
read. The program should keep asking for input until 5 unique numbers are input. Use the smallest possible array to solve this program. Display the complete set of unique values input after the user enters each new value.
I'm stuck. Everything works correctly except for the nested if loop. It always accepts this for true. Any ideas on how I might rearrange my code to make this work properly? Thanks in advance!
Also, I apologize for the sloppy code. I don't know how to make it translate to look pretty on here.
import java.util.Scanner;
public class UniqueTest {
public static void main(String[] args) {
//declare an array with 5 elements
int num[] = new int[5];
int index = 0;
Scanner input = new Scanner(System.in);
//declare the input object (she didn't do this for us)
while(index < num.length){
System.out.println("Enter an integer between 10 and 100: ");
//accept a keyboard input and assign it to a variable
int number = input.nextInt();
if (number>=10&&number<=100)
{
++index;
num[index] += number;
System.out.printf("%d\n", num[index]);
if (number == num[index])
{
System.out.println("Value has already been entered.");
}
}
else
{
System.out.println("Error: You did not enter a number between 10 and 100.");
}
}
}
}