-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//ini merupakan basic contoh untuk ternary operator | ||
//ternary operator ialah sambungan kepada if else untuk memendekkan code | ||
//didalam code ini akan check string dimana a iaitu variable kepada fikri sama dengan ahmad atau tidak | ||
//selepas tanda ? akan berlaku string iaitu true or false | ||
//jika true, sistem akan print betul | ||
//jika salah sistem akan print salah | ||
// tanda colon iaitu =: digunakan untuk membezakan true or false | ||
//output coding ini ialah salah | ||
|
||
/* | ||
public class TernaryIfElse { | ||
public static void main(String[] args){ | ||
String a = "fikri"; | ||
String result = (a=="ahmad")? "betul" : "salah"; | ||
System.out.println(result); | ||
} | ||
} | ||
*/ | ||
|
||
|
||
//ini merupakan contoh selanjutnya untuk ternary operator untuk melihat semua kebarangkali selain guna switch | ||
//output coding ini ialah gemok | ||
|
||
|
||
public class TernaryIfElse{ | ||
public static void main(String[] args){ | ||
int weight = 97 ; | ||
|
||
|
||
String result = (weight == 60 )? "kurus" : | ||
(weight == 70 )? "kurus" : | ||
(weight == 80 )? "kurus" : | ||
(weight >= 90 )? "gemok" : "obes"; | ||
|
||
System.out.println(result); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//ini merupakan contuh coding untuk ifelse | ||
//dimana logik coding ialah=c lebih atau sama dengan 20 atau | ||
//c kurang dari 20 iaitu 19 | ||
//output untu coding ini ialah "ahmad dh besar" | ||
|
||
|
||
public class elseifExample { | ||
public static void main(String[] args){ | ||
String a = "ahmad", b = "amin"; | ||
int c = 20 , d = 21; | ||
|
||
System.out.println(a + " berumur " + d +" tahun"); | ||
System.out.println(b+ " berumur " + c + " tahun"); | ||
|
||
if(c >=20){ | ||
System.out.println("Ahmad dh besar"); | ||
} | ||
else if(c < 20){ | ||
System.out.println("Ahmad masih kecil"); | ||
} | ||
else{ | ||
System.out.println("ahmad masih bayi"); | ||
} | ||
|
||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//ini merupakan contoh coding untuk "if" | ||
//variable x yang di store ialah 20 | ||
//mengikut logik if dibawah, jika x kurang dari 30 dimana x kita ialah 20, system akan print "that is good bruh" | ||
|
||
|
||
public class ifExample { | ||
public static void main(String[] args){ | ||
int x = 20; | ||
|
||
if(x < 30){ | ||
System.out.println("that is good bruh"); | ||
} | ||
else{ | ||
System.out.println("That dope man"); | ||
} | ||
|
||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//ini merupakan contoh untuk function Math di java lang | ||
//funtion Math.max(x,y) digunakan untuk mengularkan output yang paling besar di antara nombor sequence | ||
//function ini hanya boleh mengunakan 2 int sahaja iaitu (x,y) sahaja | ||
//outout untuk coding ini ialah 200 | ||
|
||
/* | ||
public class math { | ||
public static void main(String[] args){ | ||
System.out.println(Math.max(100,200)); | ||
} | ||
} | ||
*/ | ||
|
||
//untuk coding di bawah pula function untuk Math.min | ||
//dimana ia akan mengeluarkan integer yang paling kecil diantara (x,y) | ||
//output coding ini ialah 499 | ||
|
||
/* | ||
public class math{ | ||
public static void main(String[] args){ | ||
System.out.println(Math.min(500,499)); | ||
} | ||
} | ||
*/ | ||
|
||
|
||
//ini merupakakan contoh coding untuk square root | ||
//function Math.sqrt(x) digunakan untuk mengeluarkan nilai square root dari nombor yang diberikanth.sqrt(x) digunakan | ||
//output coding ini ialah 14.142135623730951 | ||
|
||
/* | ||
public class math{ | ||
public static void main(String[] args){ | ||
System.out.println(Math.sqrt(200)); | ||
} | ||
} | ||
*/ | ||
|
||
|
||
//ini merupakan function coding untuk absolute number | ||
//teori absolute ialah akan sentiasa return nombor negatif ke nombor positif | ||
//dengan cara absolute akan menghilangkan tanda negatif (-9=9) | ||
//output coding ini ialah 9 | ||
|
||
/* | ||
public class math{ | ||
public static void main(String[] args){ | ||
System.out.println(Math.abs (-9)); | ||
} | ||
} | ||
*/ | ||
|
||
//coding dibawah menunjukkan function untuk Math.random() | ||
//dimana didalam bracket ialah parameter untuk nombor random | ||
//function random ini akan mengeluarkan output dari 0.0 hingga 0.9999999999999999 sahaja | ||
//output coding ini ialah 0.5742394791370464 | ||
|
||
/* | ||
public class math{ | ||
public static void main(String[] args){ | ||
System.out.println(Math.random()); | ||
} | ||
} | ||
*/ | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public class switchExample { | ||
|
||
} |