So this is my code so far, the user can input values and store them in an array. However what im trying to make is that the user input be between the range 1 and 50, if its outside of this range then i want some error message to print stating the range isnt between 1 and 50, and if the value is outside of the range, i want the loop to repeat until the user fills the array within the range 1 and 50. How should i go along to get these things done ?
import java.util.Scanner;
public class Input {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.println("Please input a positive number between 1 and 50: ");
int userNumb = input.nextInt();
int[] array = new int[10];
do {
int i = 0;
array[i] = input.nextInt();
} while (userNumb < 0 || userNumb > 50);
System.out.println("The inputed values are: ");
for (int element : array) {
System.out.println(element + ",");
}
}
}