Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Easiest way<br> So what I do is first ask the number. Then save the number in a variable before entering it inside the array. Then I check if that number is already in it wih search. If it is I ask for a new number. If it is not I check if it is between 10 and 100, if it is not I ask for a new. I fit is I enter It inside the array. I have to check where an empty place is because the sort mixes up the array everytime</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++){ System.out.println("Please type a number between 10 and 100: "); int number = in.nextInt(); //while (InpNum[i] &lt;= i){ while (Search(InpNum, number) == true){ System.out.println("ERROR: Please enter a number that is not a duplicate of the other numbers you have entered"); number = in.nextInt(); } while (number &lt; 10 || number &gt; 100){ System.out.println("Error: Please type an integer between 10 and 100: "); number = in.nextInt(); } int counter = 0; for (int j = 0; j &lt; InpNum.length &amp;&amp; counter == 0; j++){ if(InpNum[j] == 0){ InpNum[j] = number; counter++; } } Arrays.sort(InpNum); System.out.println(Arrays.toString(InpNum)); //} } } // I can't seem to implement the method below in a useful manner. public static boolean Search(int InpNum[], int searchedNum) { for (int i = 0; i &lt; InpNum.length; i++){ if (InpNum[i] == searchedNum) { return true; } } return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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