Java: String input in console and parsing in Int

The following are requirements.

Input: The first line of input will consist of the number N, the number 9 * 9 of the matrix. The next N * 9 lines will contain puzzles in the specified format.

Conclusion: The only number that is the sum of all numbers on the main diagonals of all given puzzles.

Below is the code I wrote: ( Is the logic correct? Why doesn't it display the desired result ?)

import java.util.Scanner;

class TheInvitationGame{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[][][] = new int[n][9][9];
int arr[][] = new int [10][9];

int sum = 0;
String inpline[][] = new String[n][9];

for(int k=0; k<n; k++){
    for(int i=0; i<9; i++){
        inpline[k][i] = sc.next();

        for(int j=0; j<9; j++){
            a[k][i][j] = inpline[k][i].charAt(j);
            if(i==j){
                sum += a[k][i][j];      
            }   
        }
        System.out.println();
    }
}

System.out.println(sum);

}
}

Here I want to take a 3D array [k] [i] [j], in which k is used to repeat NO. of 9 * 9 input matrices, i = string (in String format) that the user enters, j = no. columns in the matrix, which will also serve as the variable charAt ()

: ( 464 32 (0 + 2 + 4 + 6 + 8 + 0 + 2 + 4 + 6)

1 012345678

123456789

234567890

345678901

456789012

567890123

678901234

789012345

890123456

464

+4
3

, char int, .

a[k][i][j] = inpline[k][i].charAt(j);

, , ASCII, char, int. .
substring(), , int Character.getNumericValue(Char ch). int char. ,

a[k][i][j] = Character.getNumericValue(inpline[k][i].charAt(j));

. .

. API Java.

+1

(j, j + 1); charAt (j); int.

0

charAt char, Integer.parseInt() String. varName [i] [k].substring(j, j + 1), j - .

0

Source: https://habr.com/ru/post/1570783/


All Articles