Код | import java.util.Scanner; public class Main { static int[][] A1,A2,A; static int x1,y1,x2,y2; public static void main(String[] args) { input(); mnoj(); output(); } public static void input() { Scanner scan = new Scanner(System.in); System.out.println("Введите размерность первой матрицы(x,y):"); System.out.print("\nx="); x1=scan.nextInt(); System.out.print("\ny="); y1 = scan.nextInt(); A1=new int[x1][y1]; x2=y1; System.out.println("Введите размерность второй матрицы(y; x будет равен y первой матрицы ):"); System.out.print("\ny="); y2 = scan.nextInt(); A1=new int[x2][y2]; A=new int[x1][y2]; System.out.println("Введите элементы первой матрицы:"); for(int i=0;i<x1;i++) { System.out.println("\n"+i+" строка:"); for(int j=0;j<y1;j++) { System.out.print("\ny"+j+"="); A1[i][j]= scan.nextInt(); } } System.out.print("\n Вторая матрица"); for(int i=0;i<x2;i++) { System.out.println("\n"+i+" строка:"); for(int j=0;j<y2;j++) { System.out.print("\ny"+j+"="); A2[i][j]= scan.nextInt(); } } } public static void output() { String s=""; System.out.print("\n"); for(int i=0;i<x1;i++) { for(int j=0;j<x1;j++) { s+=A[i][j]+" "; } System.out.print(s); } } public static void mnoj() { for(int j=0;j<x1;j++) { for(int i=0;i<y2;i++) { A[i][j]=0; for(int a=0;a<y1;a++) { A[i][j]+=A1[i][a]*A2[a][j]; } } } } }
|
Ошибка начинается во время ввода элементов второй матрицы - в классе input, строке этак на 43. На скрине я оставил пример того что происходит. Кстати, можете посоветовать какуюнить нормальную проверку на ввод? Ато какую проверку я не делаю, ввод начинает багать еще больше. |