Last active
November 5, 2025 14:15
-
-
Save solanoize/bcee35f55e5fceeed73d397f239de8b7 to your computer and use it in GitHub Desktop.
SQA Batch 25 Day 04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.juaracoding.labs; | |
| public class App { | |
| public static void main(String[] args) throws Exception { | |
| int[] nilaiPeserta = {1, 4, 6, 8, 1}; | |
| // 0 1 2 3 4 | |
| System.out.println(nilaiPeserta[0]); | |
| // System.out.println(nilaiPeserta[6]); // error: diluar jangkauan | |
| int[] komplekDinas = new int[5]; | |
| komplekDinas[0] = 3; | |
| komplekDinas[1] = 2; | |
| komplekDinas[2] = 10; | |
| komplekDinas[3] = 1; | |
| komplekDinas[4] = 15; | |
| System.out.println(komplekDinas[2]); | |
| System.out.println("Perulangan dengan array"); | |
| for (int i = 0; i < komplekDinas.length; i++) { | |
| System.out.println(komplekDinas[i]); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.juaracoding.labs; | |
| public class App { | |
| public static void main(String[] args) throws Exception { | |
| int[] subtotal = { | |
| 30000, | |
| 15000, | |
| 12000, | |
| 50500, | |
| 123000 | |
| }; | |
| int total = 0; | |
| // iterasi item array versi old | |
| // for (int i = 0; i < subtotal.length; i++) { | |
| // total = total + subtotal[i]; | |
| // } | |
| // iterasi item array versi zaman now | |
| for (int harga: subtotal) { | |
| total = total + harga; | |
| } | |
| System.out.println("Total: " + total); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.juaracoding.labs; | |
| public class App { | |
| public static void main(String[] args) throws Exception { | |
| int[][] map = { | |
| { 1, 10, 5, 4 }, | |
| { 4, 6, 4, 7 }, | |
| }; | |
| for (int[] row: map ) { | |
| for (int col: row) { | |
| System.out.println(col); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.juaracoding.labs; | |
| import java.util.Arrays; | |
| public class App { | |
| public static void main(String[] args) throws Exception { | |
| int[][] belanja = { | |
| {10, 10000, 0, 15000, 0}, | |
| {23, 24000, 0, 5000, 0}, | |
| {11, 14000, 0, 0, 0}, | |
| }; | |
| int i = 0; | |
| int total = 0; | |
| for (int[] items: belanja) { | |
| belanja[i][2] = items[0] * items[1]; | |
| belanja[i][4] = belanja[i][2] - items[3]; | |
| total = total + belanja[i][4]; | |
| i++; | |
| } | |
| System.out.println("Data Belanja : " + Arrays.deepToString(belanja)); | |
| System.out.println("Total Rp. " + total); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.juaracoding.labs; | |
| import java.util.Arrays; | |
| import java.util.concurrent.ThreadLocalRandom; | |
| public class App { | |
| public static void main(String[] args) throws Exception { | |
| // int[][] belanja = { | |
| // {10, 10000, 0, 15000, 0}, | |
| // {23, 24000, 0, 5000, 0}, | |
| // {11, 14000, 0, 0, 0}, | |
| // }; | |
| // int i = 0; | |
| // int total = 0; | |
| // for (int[] items: belanja) { | |
| // belanja[i][2] = items[0] * items[1]; | |
| // belanja[i][4] = belanja[i][2] - items[3]; | |
| // total = total + belanja[i][4]; | |
| // i++; | |
| // } | |
| // System.out.println("Data Belanja : " + Arrays.deepToString(belanja)); | |
| // System.out.println("Total Rp. " + total); | |
| int[][] map = new int[4][4]; | |
| for (int r = 0; r < map.length; r++) { | |
| for (int c = 0; c < map[r].length; c++) { | |
| map[r][c] = ThreadLocalRandom.current().nextInt(0, 3); | |
| } | |
| } | |
| int diamond = 0; | |
| for (int[] i: map) { | |
| for (int c: i) { | |
| if (c == 0) { | |
| diamond += 1; | |
| } | |
| if (c == 2) { | |
| diamond -= 1; | |
| } | |
| } | |
| } | |
| System.err.println(Arrays.deepToString(map)); | |
| System.out.println(diamond); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.juaracoding.labs; | |
| public class ReverseArray { | |
| public static void main(String... args) { | |
| int[][] map = { | |
| { 1, 10, 5, 4 }, | |
| { 4, 6, 4, 7 }, | |
| }; | |
| System.out.println("Mencetak nilai dari belakang ke depan:"); | |
| // Loop untuk baris, mulai dari baris terakhir (indeks map.length - 1) | |
| for (int i = map.length - 1; i >= 0; i--) { | |
| // Loop untuk kolom, mulai dari kolom terakhir (indeks map[i].length - 1) | |
| for (int j = map[i].length - 1; j >= 0; j--) { | |
| System.out.println(map[i][j]); | |
| } | |
| } | |
| } | |
| } |
Author
solanoize
commented
Nov 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment