Berhubung lagi bantuin tugas temen tentang matriks, sekarang saya share coding untuk menginputkan matriks dengan java.
Codingny:
import java.io.*;
public class matriks{
private static BufferedReader stdin=new BufferedReader (new InputStreamReader(System.in));
public static void main (String[]args) throws Exception {
System.out.println ("Membuat Matrix");
System.out.println ("=====================================================================");
System.out.println ("Masukkan Jumlah Baris: ");
String input1 = stdin.readLine ();
int baris =Integer.parseInt(input1);
System.out.println ("Masukkan Jumlah Kolom: ");
String input2 = stdin.readLine ();
int kolom=Integer.parseInt (input2);
int [][]matrix1= new int [baris][kolom];
System.out.println ();
System.out.println("Masukkan Elemen Matrik");
System.out.println("=====================================================================");
for(int x=0;x<baris;x++)
{ int indexbaris1=x+1;
for(int y=0;y<kolom;y++)
{ int indexkolom1 =y+1;
System.out.println ("masukan elemen ke["+indexbaris1+","+indexkolom1+"]");
String mtx1=stdin.readLine();
matrix1[x][y]=Integer.parseInt(mtx1);
}
}
System.out.println ();
System.out.println("Matrix");
for(int x=0;x<baris;x++)
{ System.out.print("|");
for(int y=0;y<kolom;y++)
System.out.print(matrix1[x][y]+" ");
System.out.println("| ");
}
}
}
public class matriks{
private static BufferedReader stdin=new BufferedReader (new InputStreamReader(System.in));
public static void main (String[]args) throws Exception {
System.out.println ("Membuat Matrix");
System.out.println ("=====================================================================");
System.out.println ("Masukkan Jumlah Baris: ");
String input1 = stdin.readLine ();
int baris =Integer.parseInt(input1);
System.out.println ("Masukkan Jumlah Kolom: ");
String input2 = stdin.readLine ();
int kolom=Integer.parseInt (input2);
int [][]matrix1= new int [baris][kolom];
System.out.println ();
System.out.println("Masukkan Elemen Matrik");
System.out.println("=====================================================================");
for(int x=0;x<baris;x++)
{ int indexbaris1=x+1;
for(int y=0;y<kolom;y++)
{ int indexkolom1 =y+1;
System.out.println ("masukan elemen ke["+indexbaris1+","+indexkolom1+"]");
String mtx1=stdin.readLine();
matrix1[x][y]=Integer.parseInt(mtx1);
}
}
System.out.println ();
System.out.println("Matrix");
for(int x=0;x<baris;x++)
{ System.out.print("|");
for(int y=0;y<kolom;y++)
System.out.print(matrix1[x][y]+" ");
System.out.println("| ");
}
}
}
semoga artikel ini juga dapat membantu sobat ilmu212 semuanya.
Tidak ada komentar:
Posting Komentar
JANGAN LUPA BERKOMENTAR DAN UNGKAPKAN PENDAPAT ANDA TENTANG ARTIKEL INI.
NO SARA
NO PORNOGRAFI
NO SPAM
NO LINK ON
NO LINK OFF
JANGAN LUPA UNTUK SELALU MEMBAGIKAN ARTIKEL INI KE JEJARING SOSIAL YANG ANDA SUKA YA :)