I know this error comes when we insert an element in the index which is greater than the size of an array but I still can't figure out why I am getting such an issue I have analyzed code very well but can't figure out the issue.
/*package whatever //do not write package name here */
import java.util.*;
import java.lang.*;
import java.io.*;
class Test {
public static void main (String[] args) {
//code
Scanner sc = new Scanner(System.in);
System.out.println("Enter T value");
int t = sc.nextInt();
while(t > 0){
System.out.println("Enter Array Size");
int n = sc.nextInt();
int a[] = new int[n];
System.out.println("Enter Array Element");
for(int i = 0;i<n; i++){
a[i] = sc.nextInt();
}
for(int i = 0; i<n; i++){
int min = i;
for(int j = i; j<n;j++){
if(a[j] < a[min]){
min = a[j];
}
}
int temp = a[i];
a[i] = a[min];
a[min] = temp;
}
for(int el : a){
System.out.print(el + " ");
}
t--;
}
}
}