How do I store the user input that is indented by a space into the String array and convert the number into int array?

I'm not that new to programming, but I had a problem when storing the user input to the string array and store it into an int array. Does anybody know how to fix my code?

This code creates an index out of bounds:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 1, end 2, length 1

    import java.util.*;

    public class Main
    {
        public static void main(String[] args) 
        {
            // Variable Declarations & Initializations
            Scanner input = new Scanner(System.in);     
            int k = input.nextInt();
            int[] num = new int[k];
            String[] store = new String[k];
            for(int i = 0; i < k; i++)
            {
                String[] paint = input.next().split(" ");
                store[i] = paint[0];
                num[i] = Integer.parseInt(paint[1]);
            }//end loop
         }//end main
      ]//end class
    


Read more here: https://stackoverflow.com/questions/66282090/how-do-i-store-the-user-input-that-is-indented-by-a-space-into-the-string-array

Content Attribution

This content was originally published by Kevin Kim at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: