Cannot take input of string array

in this code when i put n=3 then start entering inputs it gives error after i have written the second line

import java.util.*;

public class StringInput {

public static void main(String[] args) {

    Scanner sc=new Scanner(System.in);

    int n=sc.nextInt();

    List<String> list=new ArrayList<>();

    for(int i=0;i<n;i++){

        list.add(sc.nextLine());

    }

    int cols=1;

    for(char c:list.get(0).toCharArray()){

        if(c==' ')

        cols++;

    }

    int[][] matrix=new int[n][cols];

    for(int i=0;i<n;i++){

        String[] arr = list.get(i).split(" ");

        for(int j=0;i<cols;j++){

            int element=Integer.parseInt(arr[j]);

            matrix[i][j]=element;

        }

    }

    for(int i=0;i<n;i++){

        for(int j=0;j<cols;j++)

        System.out.println(matrix[i][j]+" + ");

        System.out.println("");

    }

}

}