Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a single-dimensional array, ask the user for input and display only NON-duplicate values
    text
    copied!<p>in my java class we were learning about arrays and this question came up. I have tried to solve it and can't seem to fulfill the requirements. I can read in the user inputs and have it limited to only 5 elements (one of the other requirements), also the values have to be between 10 and 100 I have also done that. But I cannot seem to "not print" the duplicate values. The array accepts the duplicate values. They don't have to be taken out, just not printed. Here is my code so far:</p> <pre><code>import java.util.Arrays; import java.util.Scanner; public class ArrayTest { static Scanner in = new Scanner(System.in); public static void main(String[] args) { int size = 5; int InpNum[] = new int[size]; for (int i = 0; i &lt; InpNum.length; i++){ while (InpNum[i] &lt;= i){ System.out.println("Please type a number between 10 and 100: "); InpNum[i] = in.nextInt(); while (InpNum[i] &lt; 10 || InpNum[i] &gt; 100){ System.out.println("Error: Please type an integer between 10 and 100: "); InpNum[i] = in.nextInt(); } Arrays.sort(InpNum); System.out.println(Arrays.toString(InpNum)); } while (Search(InpNum, i) == true){ System.out.println("ERROR: Please enter a number that is not a duplicate of the other numbers you have entered"); InpNum[i] = in.nextInt(); } } } // I can't seem to implement the method below in a useful manner. public static boolean Search(int InpNum[], int searchedNum) { for(int i : InpNum) { if (i == searchedNum) { return true; } } return false; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload