berikut contoh program searching pada array dalam java menggunakan i/o java.util.Scanner
import java.util.Scanner;
class scr{
public static void main(String[] args){
int[][] Mat1 = new int[3][4];
Scanner s = new Scanner(System.in);
System.out.print("\n-Input Matriks-\n");
InputMatriks(Mat1);
System.out.print("\n-Matriks-\n");
tampilMatriks(Mat1);
System.out.print("\n Masukan variabel yang anda cari : "); int cari = s.nextInt();
cariMatriks(Mat1,cari);
}
public static void InputMatriks(int[][] matriks1){
Scanner scansod = new Scanner(System.in);
for(int i=0; i
for(int j=0; j
System.out.print(" Masukan elemen matriks A["+(i+1)+"]["+(j+1)+"]:");
matriks1[i][j]=scansod.nextInt();
}
}
}
public static void tampilMatriks(int[][] matriks){
for(int i=0; i
for(int j=0; j
System.out.print(" "+matriks[i][j]);
}System.out.print("\n");
}
}
public static void cariMatriks(int[][] matriks, int cari){
for(int i=0; i
for(int j=0; j
if(matriks[i][j]==cari){
System.out.print(" Variabel "+cari+" ada di matriks dengan baris "+(i+1)+" kolom "+(j+1)+"\n\n");
}
}
}
}
}
class scr{
public static void main(String[] args){
int[][] Mat1 = new int[3][4];
Scanner s = new Scanner(System.in);
System.out.print("\n-Input Matriks-\n");
InputMatriks(Mat1);
System.out.print("\n-Matriks-\n");
tampilMatriks(Mat1);
System.out.print("\n Masukan variabel yang anda cari : "); int cari = s.nextInt();
cariMatriks(Mat1,cari);
}
public static void InputMatriks(int[][] matriks1){
Scanner scansod = new Scanner(System.in);
for(int i=0; i
for(int j=0; j
System.out.print(" Masukan elemen matriks A["+(i+1)+"]["+(j+1)+"]:");
matriks1[i][j]=scansod.nextInt();
}
}
}
public static void tampilMatriks(int[][] matriks){
for(int i=0; i
for(int j=0; j
System.out.print(" "+matriks[i][j]);
}System.out.print("\n");
}
}
public static void cariMatriks(int[][] matriks, int cari){
for(int i=0; i
for(int j=0; j
if(matriks[i][j]==cari){
System.out.print(" Variabel "+cari+" ada di matriks dengan baris "+(i+1)+" kolom "+(j+1)+"\n\n");
}
}
}
}
}
No comments:
Post a Comment