My code below has a exception error for:
YN = input.nextLine().charAt(0); //line 13
when it is run. The assignment is to make an array that is assigned 10 numbers from console, when I put in 10 numbers the run completes automatically and gives an error for line 13. Is there something wrong with line 13 or is the issue with something else?
(The array must be a normal array and not an arrayList)
import java.util.*;
import java.util.Arrays;
public class CountOccurrences {
static Scanner input = new Scanner(System.in);
static int[][] temp = new int[10][1];
public static void main(String[] args) {
char YN = 'y';
while (YN == 'y') {
run();
System.out.print("Continue? (y or n)\t");
YN = input.nextLine().charAt(0); // Line 13
}
}
public static void run() {
System.out.print("Enter the integers between 1 and 100: ");
int[] numbersArray = new int[10];
for (int i = 0; i < numbersArray.length; i++) {
numbersArray[i] = input.nextInt();
}
for (int i = 0; i < numbersArray.length; i++) {
Arrays.sort(numbersArray);
System.out.println(numbersArray[i]);
}
}
}