program java membuat, membagi matriks dengan jumlah diagonal, mentranfus matriks....
catatan(harus sama baris dan kolomnya...) :)
import java.util.Scanner;
public class Jummat {
static Scanner x= new Scanner(System.in);
public static void main(String[] args) {
int b,k,hasil = 0,hasil1=0;
System.out.print("Masukkan baris : ");b = x.nextInt();
System.out.print("Masukkan kolom : ");k = x.nextInt();
if (b == k){
System.out.println("Matriks 1 : ");
int mt1[][] = new int[b][k];
for(int i=0;i<b;i++){
for(int j=0;j<k;j++){
System.out.print("Bil baris ke-"+(i+1)+" kolom ke-"+(j+1)+" : ");mt1[i][j] = x.nextInt();
}
}
System.out.println("Matriks 1 : ");
for(int i=0;i<b;i++){
for(int j=0;j<k;j++)
System.out.print(mt1[i][j] + " ");
System.out.println();
}
for (int i=0;i<b;i+=1) {
for(int j=0;j<k;j++)
if (i==j)
hasil=hasil+mt1[i][j];
}
System.out.println("Hasil Penjumlahan Diagonal matriks adalah : "+hasil);
System.out.println("");
System.out.println("Mastriks setelah dibagi diagonal : ");
for (int i = 0; i < b; i++) {
for (int j = 0; j < k; j++) {
System.out.print(String.format("%.2f",(float)mt1[i][j]/hasil) + " ");
}
System.out.println("");
}
System.out.println("");
System.out.println("Matriks setelah ditransfus : ");
for (int i = 0; i < b; i++) {
for (int j = 0; j < k; j++) {
System.out.print(String.format("%.2f",(float) mt1[j][i]/hasil)+" ");
}
System.out.println("");
}
System.out.println("Terima Kasih :)");
}
else
System.out.println("Maaf Matriks harus persegi...Ex.3x3 or etc");
}
}
selamat mencoba semoga bermanfaat......:)
Tidak ada komentar:
Posting Komentar