java - Scalar Multiplication -
edit question this: scalar multiplication defined b = * s, b , equally sized matrices (2d array of numbers, in example let's use integers) , s scalar value. each element of multiplied s, stored in corresponding element in matrix b.
write program accepts 4x4 matrix , scalar value, , perform scalar multiplication, storing result in separate 4x4 matrix.
import java.util.*; public class arrayexercises {  public static void main (string [] args){  //scalar value   scanner sc = new scanner (system.in); int scalar = 0;  //array int matrix [][]; matrix = new int [4][4];  system.out.println("enter numbers in 4x4 matrix"); (int i=0; < matrix.length; i++)     {     (int j =0; j<matrix[i].length; j++)         matrix[i][j] = sc.nextint();     }  system.out.println("enter scaler value:"); scalar = sc.nextint();    sc.close();  }   }
not giving direct solution. giving hint instead.
so far code, have created matrix , withing 2 loop have set values of matrix user input.
now scalar multiplication need similar operation. create matrix of same size previous matrix. , in similar way within 2 loop multiply each , every element of old matrix scalar value , set coresponding index of new matrix.
Comments
Post a Comment