_stan
Ominide
1 min. di lettura
Vota

Concetti Chiave

  • The method moltiplicaDueRighe multiplies two specified rows from a given matrix M.
  • It takes three arguments: the matrix M and two integers R1 and R2 representing the row indices.
  • The method calculates the sum of products of corresponding elements from the specified rows.
  • An example is provided where the method computes the result as 50 from the given matrix and row indices.
  • The implementation uses a single loop to iterate through the elements of the specified rows.

Tema 45

Scrivere un metodo moltiplicaDueRighe che riceve in ingresso una matrice M e due interi R1 ed R2 e restituisce il risultato del prodotto tra la riga R1 e la riga R2.
Ad esempio, sia M la matrice così costituita
1 2 3 4
1 4 5 3
3 5 6 1
2 3 6 2
allora moltiplicaDueRighe(M, 1, 3) = (1x2)+(4x3)+(5x6)+(3x2) = 50
 public class tema45 { public static int moltiplicaDueRighe (int[][] M, int R1, int R2) { // prepariamo un contenitore di tipo intero in cui effettueremo le operazioni int calcolo = 0; // è sufficiente un solo ciclo visto che gli indici di riga sono valori noti for (int j = 0; j 

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community