Rabu, 24 Mei 2017

array 2 dimensi


Array 2 dimensi

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaarrai2dimesi1;

import java.util.Scanner;

/**
 *
 * @author rachmad r.
 */
public class JavaArrai2dimesi1 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

String[][] array = new String[4][4];
int cek;
        @SuppressWarnings("UnusedAssignment")
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 (String[] array1 : array) {
        for (int j = 0; j<array.length; j++) {
            System.out.print("|" + array1[j] + "|");
            bintang = array1[j];
            cek = bintang.indexOf("4");
            array1[j] = cek>=0 ? "**" : array1[j];
        }
        System.out.println("");
    }
                System.out.println("------------------------------------");
                System.out.println("");
                System.out.println("Hasil Nilai Berubah");
    for (String[] array1 : array) {
        for (int j = 0; j<array.length; j++) {
            System.out.print("|" + array1[j] + "|");
        }
        System.out.println();
    }
}
}

Hasil Nilai Inputan
|1||2||3||4|
|1||2||3||4|
|1||2||1||2|
|1||2||1||1|
------------------------------------

Hasil Nilai Berubah
|1||2||3||**|
|1||2||3||**|
|1||2||1||2|
|1||2||1||1|

BUILD SUCCESSFUL (total time: 19 minutes 22 seconds)


Rachmad ramadhan
1655201084
Teknik Informatika S1

Tidak ada komentar:

Posting Komentar