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 ((

  • Do you like the design of the code yourself? - Stas0n
  • Eclipse for the second time in my life I see, as much as I could> < - noel
  • one
    Sorry, comments related to the formatting of the text in the topic. As for the code, the writing does not depend on what you write on) Beauty does not depend on either the eclipse or the netbin .. - Stas0n
  • Why do people use BufferedReader if Scanner is 100 times simpler and more convenient? - kandi

2 answers 2

  1. Declare mas, min, max as double
  2. Parse a real number like Double.parseDouble()
  3. And jogging indexes in Java starts from zero
  4. When finding the minimum, the initial value of the minimum is usually set as Double.POSITIVE_INFINITY , and for the maximum, respectively, as Double.NEGATIVE_INFINITY - then this ensures that the minimax is correctly found.
  5. I wouldn’t throw Exception right away from main , better take everything in a try-catch block with intelligent printStackTrace()
  • swears that i and j are of integer type, and everything else is real - noel
  • 3
    @noel oh my goodness, don't make a compiler out of me then! Most likely, k_min and k_max declared double , and you must have an int . The meaning boils down to the fact that double should be everything that relates to the elements of the matrix, and everything that relates to the indices of the matrix is ​​integer. - Barmaley
  • Everything, I did, thank you - noel
  • @noel if the answer is accepted, then in this forum it is customary to click on the check mark on the left side of the accepted answer, otherwise the next time you may not be helped :) - Barmaley
  • In general, I made a float through the result, but it does not matter) - noel

For real use Double.parseDouble instead of Integer.parseInt () + replace all int with double.
Now for the dot product: why ask the number of rows and the number of columns of the matrix separately, if it should be square?