Senin, 15 Mei 2017

Soal :
Buat aplikasi dengan Array 2 Dimensi ketentuan :
- jumlah Baris 4
- jumlah Kolom 4
- user menginput nilai (angka- 2digit) pada setiap kombinasi baris dan kolom

- 1. system menampilkan nilai yang di input
- 2. jika ada nilai yang di input terdapat angka 4, maka nilai diganti dengan karakter '**'


Penyelesaian :




package triyanto.tugas.data;

import java.util.Scanner;

public class Tugas {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

String[][] array = new String[4][4];
int cek;
String bintang = "";
for(int i=0;i<array.length;i++){
for(int j=0;j<array.length;j++){
System.out.print("Input Angka baris["+i+"]"+" kolom["+j+"]= ");
array[i][j] = scan.next();
}
System.out.println("\n");
}
                System.out.println("\n");
                System.out.println("Hasil Nilai Inputan");
for(int i=0;i<array.length;i++){
for(int j=0;j<array.length;j++){
System.out.print("|"+array[i][j]+"|");
                                bintang = array[i][j];
       cek = bintang.indexOf("4");
array[i][j] = cek>=0?"**":array[i][j];
}
System.out.println("");
}
                System.out.println("------------------------------------");
                System.out.println("");
                System.out.println("Hasil Nilai Berubah");
for(int i=0;i<array.length;i++){

for(int j=0;j<array.length;j++){
System.out.print("|"+array[i][j]+"|");
}
System.out.println();
}
}
}



OUTPUT :

run:
Input Angka baris[0] kolom[0]= 11
Input Angka baris[0] kolom[1]= 12
Input Angka baris[0] kolom[2]= 13
Input Angka baris[0] kolom[3]= 14


Input Angka baris[1] kolom[0]= 22
Input Angka baris[1] kolom[1]= 23
Input Angka baris[1] kolom[2]= 24
Input Angka baris[1] kolom[3]= 25


Input Angka baris[2] kolom[0]= 33
Input Angka baris[2] kolom[1]= 34
Input Angka baris[2] kolom[2]= 35
Input Angka baris[2] kolom[3]= 36


Input Angka baris[3] kolom[0]= 44
Input Angka baris[3] kolom[1]= 43
Input Angka baris[3] kolom[2]= 56
Input Angka baris[3] kolom[3]= 40


Hasil Nilai Inputan
|11||12||13||14|
|22||23||24||25|
|33||34||35||36|
|44||43||56||40|
------------------------------------
Hasil Nilai Berubah
|11||12||13||**|
|22||23||**||25|
|33||**||35||36|
|**||**||56||**|

BUILD SUCCESSFUL (total time: 33 seconds)

1 komentar:

  1. Best Online Casino Sites and Bonuses
    You can play online casino games for real money at ChoGiocasino Casino. Play on 카지노사이트 all the casino sites, all of which accept US 바카라 사이트 players. kadangpintar

    BalasHapus