EDIT 問題是這樣的:標量乘法被定義爲B = A * s,其中B和A是相同大小的矩陣(數2D陣列,在這個例子中,讓我們使用整數)和s是標量值。將A的每個元素乘以s,然後將其存儲在矩陣B中的相應元素中。標量乘法
編寫接受4x4矩陣和標量值的程序,並執行標量乘法,將結果存儲在單獨的4x4矩陣。
import java.util.*;
public class arrayExercises {
public static void main (String [] args){
//Scalar Value
Scanner sc = new Scanner (System.in);
int scalar = 0;
//Array for A
int matrix [][];
matrix = new int [4][4];
System.out.println("Enter the numbers in the 4x4 matrix");
for (int i=0; i < matrix.length; i++)
{
for (int j =0; j<matrix[i].length; j++)
matrix[i][j] = sc.nextInt();
}
System.out.println("Enter scaler value:");
scalar = sc.nextInt();
sc.close();
}
}
問題是什麼? – mathematician1975
嗨。如果你表明你已經嘗試過某些東西,人們會更願意幫助你。你有沒有工作的部分解決方案? – axiom
問題是:標量乘被定義爲B = A * s,其中B和A是相同大小的矩陣(二維數組數組,在這個例子中我們使用整數),s是標量值。將A的每個元素乘以s,然後將其存儲在矩陣B中的相應元素中。 編寫接受4x4矩陣和標量值的程序,並執行標量乘法,將結果存儲在單獨的4x4矩陣中。 – Belle