Code Java Matrisk And Vektor
Code berikut saya buat untuk belajar penggunaan array untuk berhitung mulai dari pemamfaatan sisi letak array yang akan dikalikan dan kemudian ditambahkan,lebih lanjutnya silahkan pelajari codenya,"Jangan lupa doakan blog ini agar sukses selalu" Terima Kasih
#Java #CodeJava #SampleCodeJAVA #BelajarJava
package xxx.xxxx.xxxxx.xxxxxx.xxxxxxx;
public class MatrixAndVektor {
public static void main(String [] args){
int a[][] = {{2,3},{3,4}};
int b[] = {3,2};
int result [][] = new int[2][2];
int temp[][] = new int[2][2];
int answer[] = new int[2];
int tempData[][] = new int[2][2];
for(int ax = 0;ax<a.length;ax++)
{
for(int az = 0;az<a.length;az++){
System.out.println(" a = " +a[ax][az]);
}
}
for(int r = 0;r<a.length;r++){
for(int t = 0;t<a.length;t++){
tempData[r][t]=a[t][r];
System.out.println(" tempData = "+tempData[r][t]);
}
}
for (int f = 0;f<b.length;f++){
for (int g = 0;g<b.length;g++){
result[f][g] = tempData[f][g] * b[f];
System.out.println(" result : "+result[f][g]);
}
}
System.out.println("result 0 0 :"+result[0][0]);
System.out.println("result 0 1 :"+result[0][1]);
System.out.println("result 1 0 :"+result[1][0]);
System.out.println("result 1 1 :"+result[1][1]);
System.out.println(b.length + "b length");
/* temp[1][0] = result[0][1];
temp[1][1] = result[1][1];*/
int turun = 1;
for(int x = 0;x<result.length;x++){
for (int y = 0;y<result.length;y++){
temp[x][y]=result[x][y];
if(x==1 && y ==0){
temp[x][y]=result[y][x];
}
else if(x==1 && y==1){
temp[turun-x][y]=result[y][turun-x];
break;
}
}
}
//menampilkan temp
for(int xy=0;xy<temp.length;xy++){
for (int xz=0;xz<temp.length;xz++){
System.out.println("temp ["+xy+"] ["+xz+"] "+temp[xy][xz]);
}
}
//perhitungan tambah
for(int q = 0;q<temp.length;q++){
for (int w = 0;w<temp.length;w++){
System.out.println("[q] = "+q);
answer[q]=temp[q][w]+temp[q][++w];
System.out.println("answer[q] = "+answer[q]);
}
}
System.out.println(" answer : " + answer[0]);
System.out.println(" answer : " + answer[1]);
}
}
Komentar
Posting Komentar