diff --git a/BlnTahun.java b/BlnTahun.java new file mode 100644 index 0000000..a51fd54 --- /dev/null +++ b/BlnTahun.java @@ -0,0 +1,33 @@ +public class BlnTahun{ + public static void main(String[] args){ + if(args.length != 2){ + System.out.println("Usage: MonthFromNumber "); + return; + } + int bln= Integer.parseInt(args[0]); + int thn= Integer.parseInt(args[1]); + int hri=0; + + switch(bln){ + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + hri=31; break; + case 2: hri=((thn%4==0) && !(thn%100==0) || (thn%400==0)) ? 29 : 28; break; + case 4: + case 6: + case 9: + case 11: + hri=30; break; + default: System.out.println("Maaf Anda hanya bisa memasukkan bulan dari 1-12!"); break; + } + if(hri==31) System.out.println("Hari=31"); + else if(hri==30) System.out.println("Hari=30"); + else if(hri==29) System.out.println("Hari=29"); + else if(hri==28) System.out.println("Hari=28"); + } +} \ No newline at end of file diff --git a/BubbleSort.java b/BubbleSort.java new file mode 100644 index 0000000..fd79f13 --- /dev/null +++ b/BubbleSort.java @@ -0,0 +1,28 @@ +public class BubbleSort{ + public static void main(String[] args){ + int length = args.length; + int[] arrNum = new int[length]; + + for(int i=0; iarrNum[b+1]){ + int temp = arrNum[b]; + arrNum[b] = arrNum[b+1]; + arrNum[b+1] = temp; + } + } + + } + for(int a=0; a"); + return; + } + int x= Integer.parseInt(args[0]); + + + switch(x){ + case 1: System.out.println("Januari"); break; + case 2: System.out.println("Februari"); break; + case 3: System.out.println("Maret"); break; + case 4: System.out.println("April"); break; + case 5: System.out.println("Mei"); break; + case 6: System.out.println("Juni"); break; + case 7: System.out.println("Juli"); break; + case 8: System.out.println("Agustus"); break; + case 9: System.out.println("September"); break; + case 10: System.out.println("Oktober"); break; + case 11: System.out.println("November"); break; + case 12: System.out.println("Desember"); break; + default: System.out.println("Maaf Anda hanya bisa memasukkan bulan dari 1-12!"); break; + } + } +} \ No newline at end of file diff --git a/Faktorial.java b/Faktorial.java new file mode 100644 index 0000000..1fc5060 --- /dev/null +++ b/Faktorial.java @@ -0,0 +1,16 @@ +public class Faktorial{ + public static void main(String[] args){ + if(args.length != 1){ + System.out.println("Usage: Faktorial "); + return; + } + long f=1; + int angka=0; + angka= Integer.parseInt(args[0]); + + for(int i=1; i<=angka; i++){ + f *=i; + } + System.out.println("Faktorial dari "+angka+" adalah "+f); + } +} \ No newline at end of file diff --git a/HelloWorld.java b/HelloWorld.java new file mode 100644 index 0000000..d8cbae7 --- /dev/null +++ b/HelloWorld.java @@ -0,0 +1,28 @@ +//import javax.swing.*; + +public class HelloWorld{ + public static void main(String[] args){ + //System.out.println("Hello World!"); + if(args.length != 1){ + System.out.println("Usage: LetterScore "); + return; + } + + int x= Integer.parseInt(args[0]); + + + if(x >0 && x<=20){ + System.out.println("Score = E"); + }else if(x >20 && x<=40){ + System.out.println("Score = D"); + }else if(x >40 && x<=60){ + System.out.println("Score = C"); + }else if(x >60 && x<=80){ + System.out.println("Score = B"); + }else if(x >80 && x<=100){ + System.out.println("Score = A"); + }else{ + System.out.println("Maaf, Anda hanya bisa memasukkan angka 1-100!"); + } + } +} \ No newline at end of file diff --git a/Rekursif.java b/Rekursif.java new file mode 100644 index 0000000..af31aff --- /dev/null +++ b/Rekursif.java @@ -0,0 +1,18 @@ +public class Rekursif{ + public static void main(String[] args){ + if(args.length != 1){ + System.out.println("Usage: Rekursif "); + return; + } + int n= Integer.parseInt(args[0]); + System.out.println(rek(n)); + } + + public static int rek(int n){ + if(n==0 || n==1){ + return 1; + }else{ + return n* rek(n-1); + } + } +} \ No newline at end of file