-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatriks2x2.java
44 lines (37 loc) · 1.33 KB
/
Matriks2x2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* 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.
*/
/**
*
* @author advdi
*/
import java.util.Scanner;
public class Tugas1 {
int[][] matriks = new int[2][2]; //pembuatan array dan menentukan panjangnya
public static void main(String[] args) {
Tugas1 panggil = new Tugas1(); //instantiasi objek
System.out.println("Matriks 2x2");
panggil.input(); //method input matriks
panggil.output(); //method output matriks
}
void input() {
Scanner ketik = new Scanner(System.in);
for (int baris = 0; baris < matriks.length; baris++) {
System.out.printf("Input baris %d : ", baris+1);
for (int kolom = 0; kolom < matriks.length; kolom++) {
matriks[baris][kolom] = ketik.nextInt(); //user input nilai array per baris
}
}
}
void output() {
System.out.println("===================");
for (int i = 0; i < matriks.length; i++) {
for (int j = 0; j < matriks.length; j++) {
System.out.printf("%d ", matriks[i][j]);
}
System.out.println();
}
}
}