Please tell me how to take input of string array in this case? I am get run time error

import java.util.*;

class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
int k = sc.nextInt();

        String[] arr = new String[k];
            
        for(int i=0; i<arr.length ; i++){
            
            arr[i] = sc.nextLine();
           
       }
          
         for(String val : arr){
            System.out.print(val + " ");
        }
        
        System.out.println();
        t--;
}   
    
    
}

}

You should first, take the number of test cases and the size of the array both using scanner. nextLine() because when you are accepting the first string your control is not where the string is inputted by the user.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

No… I didn’t get answer… Can you please write it in a code format… and tell me where I did mistake…

you could use, it like this.,
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int k = Integer.parseInt(in.readLine());
String A[] = new String[k];
for(int i=0;i<k;i++)A[i] = in.readLine();