There is a task
Develop a program that introduces a real matrix of arbitrary size, all the elements of which are different. Find the dot product of the row containing the largest matrix element for the column with the smallest element.
Here is the program, typing it in the eclipse
public static void main (String[]args) throws NumberFormatException,IOException { BufferedReader matr = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Введите размереность матрицы"); System.out.println("Количество строк матрицы"); int a; a = Integer.parseInt(matr.readLine())+1; System.out.println(); System.out.println("Количество столбцов матрицы"); int b; b = Integer.parseInt(matr.readLine())+1; System.out.print("Введите поэлементно матрицу"); int i,j; int[][]mas=new int[a][b]; for (i=1;i<a;i++){ for (j=1;j<b;j++){ mas[i][j]=Integer.parseInt(matr.readLine()); } } int min,max,k_min,k_max; min=mas[1][1]; max=mas[1][1]; k_min=1; k_max=1; for(i=1;i<a;i++){ for (j=1;j<b;j++){ if(mas[i][j]>=max){max=mas[i][j];k_max=i;} if(mas[i][j]<=min){min=mas[i][j];k_min=j;} } } int pr=1; for (i=1;i<a;i++){ pr=mas[i][k_min]*pr; } for(j=1;j<b;j++){ pr=mas[k_max][j]*pr; } System.out.println("Результат"); System.out.println("Исходная матрица"); for (i=1;i<a;i++){ for (j=1;j<b;j++){ System.out.print(Integer.toString(mas[i][j])+"\t"); } System.out.println(); } System.out.println("Скалярное произведение строк равно "+Integer.toString(pr)+""); }
that's just real numbers, of course, does not consider. tell me where and what you need to change the integer
. I tried to insert double
and float
, it produces errors ((