This file contains 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
public class MainActivity{ | |
public static void main(String[] args){ | |
System.out.println(" Mommy Mommy"); | |
} | |
} |
This file contains 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
int a = 5; | |
a = a + 5; // a = 10 | |
a = a - 2; // a = 8 | |
a = a * 4; // a = 32 | |
a = a / 2; // a = 16 | |
a = a % 3; // a = 1 | |
System.output.println(a); // output atau hasil yang keluar = 1 |
This file contains 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
int a = 10; | |
// contoh penggunaan operator penugasan sama dengan '=' | |
a += 10; | |
// contoh penggunaan operator penugasan ditambah '+=' | |
a -= 20; | |
// contoh penggunaan operator penugasan dikurangi'-=' | |
a *= 4; |
This file contains 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
int a = 4; | |
a++; // a ditambah satu sama dengan 5 | |
a--; // a dikurangi satu sama dengan 4 | |
System.out.println(a); // output sama dengan 4 |
This file contains 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
int a = 7; | |
int b = 7; | |
int f = 8; | |
boolean c; | |
c = b == a; // operator pembanding sama dengan '==' | |
System.out.println(c); //output yang keluar adalah true karena nilai variabel a dan b sama sama 8 | |
c = b != a; // operator pembanding tidak sama dengan '!=' | |
System.out.prinlnt(c); // output yang keluar adalah false karena nilai variabel a dan b sama sama 8 |
This file contains 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
boolean i = true; | |
boolean j = false; | |
boolean k; | |
k = i && j; // operator logika dan '&&' | |
System.out.prinlnt(k); //output yang dikeluarkan adalah false karena salah satu variabel yaitu variabel j menyimpan false | |
k = i || j; // operatir logika atau '||' | |
System.out.println(k); //output yang dikeluarkan adalah true karena salah satu variabel yaitu variabel i menyimpan nilai true |
This file contains 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
// Kerangka : | |
if (kondisi){ | |
// perintaha berupa kode yang akan dijalankan | |
} | |
/* Penjelasan : | |
kondisi berarti syarat, dimana jika syarat terpenuhi, maka diantara buka kurawal ({) dan tutup kuraawal (}) | |
akan dijalankan */ | |
// contoh ; |
This file contains 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
// Kerangka : | |
if(kondisi) { | |
//kode atau perintah yang akan dijalankan apabila kondisi terpenuhi | |
} else { | |
//kode atau perintah yang akan dijalankan apabila kondisi tidak terpenuhi | |
} | |
// Penjelasan ; | |
/* Jika kondisi benar, maka kode yang akan dijalankan program adalah kode yang berada diantara kurung kurawaal | |
buka ({) dan kurung kurawal tutup (}) milik if(kondisi). Namun, bila kondisi salah, maka kode yang akan dijalankan oleh |
This file contains 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
// Kerangka ; | |
if(kondisi A) { | |
//kode atau perintah yang dijalankan bila kondisi A bernilai true atau benar | |
}else if(kondisi B){ | |
//kode atau perintah yang dijalankan bila kondisi B bernilai true atau benar | |
}else if(kondisi C){ | |
//kode atau perintah yang dijalankan bila kondisi C bernilai true atau benar | |
} | |
/* Penjelasan : |
This file contains 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
// Kerangka ; | |
switch (variabel){ | |
case nilai1: | |
//Perintah atau kode yang akan dijalankan bila nilai1 true bila sama dengan variabel | |
break; | |
case nilai2: | |
//Perintah atau kode yang akan dijalankan bila nilai2 true bila sama dengan variabel | |
break; | |
} | |