diff --git a/bubblesort.java b/bubblesort.java new file mode 100644 index 0000000..41ab04b --- /dev/null +++ b/bubblesort.java @@ -0,0 +1,42 @@ +public class bubblesort{ + public static void main(String[] args){ + if(args.length<1){ + System.err.println("Usage: bubblesort < isi array >"); + return ; + } + + int[] arrayInteger = new int[args.length]; + + System.out.println("Before Sorting: "); + + //print all before + for(int i=0; i < arrayInteger.length; i++){ + arrayInteger[i]=Integer.parseInt(args[i]); + System.out.print(arrayInteger[i] + " "); + + } + + //sorting function + int n=args.length ; + int temp=0; + for(int i=0;iarrayInteger[j]){ + //swap elements + temp=arrayInteger[j-1]; + arrayInteger[j-1]=arrayInteger[j]; + arrayInteger[j]= temp; + } + } + } + + + System.out.println("\n\nAfter Sorting: "); + //print all after + for(int i=0; i"); + return; + } + int month = Integer.parseInt(args[0]); + switch(month){ + case 1: + System.out.println("Januari"); + break; + case 2 : + System.out.println("Febuari"); + 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( + "bukan bulan"); + } + } +} \ No newline at end of file diff --git a/faktorial.java b/faktorial.java new file mode 100644 index 0000000..3b262ed --- /dev/null +++ b/faktorial.java @@ -0,0 +1,19 @@ +public class faktorial{ + public static void main(String[] args){ + if(args.length!=1){ + System.err.println("Usage: faktorial "); + return; + } + int angka= Integer.parseInt(args[0]); + int faktorial=1; + for(int i =angka ; i>=1 ; i--){ + System.out.print(i+ " "+"\n"); + faktorial = faktorial * i; + } + + System.out.println(angka+"! = "+faktorial); + + + + } +} \ No newline at end of file diff --git a/jlh_hari.java b/jlh_hari.java new file mode 100644 index 0000000..7d4cbfc --- /dev/null +++ b/jlh_hari.java @@ -0,0 +1,41 @@ +public class jlh_hari{ + public static void main(String[] args){ + if(args.length!=2){ + System.err.println("Usage: jlh_hari "); + return; + } + int bulan= Integer.parseInt(args[0]); + int tahun = Integer.parseInt(args[1]); + + switch(bulan){ + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + System.out.println("31"); + break; + + case 4: + case 6: + case 9: + case 11: + System.out.println("30"); + break; + + case 2: + if(tahun%100==0 || tahun%100!=0 && tahun%400 == 0){ + System.out.println("29"); + } + else{ + System.out.println("28"); + } + break; + default: + System.out.println("Masukkan sesuai instruksi"); + } + + } +} \ No newline at end of file diff --git a/recfaktorial.java b/recfaktorial.java new file mode 100644 index 0000000..7809bac --- /dev/null +++ b/recfaktorial.java @@ -0,0 +1,19 @@ +public class recfaktorial{ + public static void main(String[] args){ + if(args.length!=1){ + System.err.println("Usage: recfaktorial "); + return; + } + int n = Integer.parseInt(args[0]); + System.out.println(factorial(n)); + } + + public static int factorial(int n){ + if(n == 1){ + return 1; + } + else{ + return(n *factorial(n-1)); + } + } +} diff --git a/score.java b/score.java new file mode 100644 index 0000000..0e8e9fc --- /dev/null +++ b/score.java @@ -0,0 +1,32 @@ +public class score{ + public static void main(String[] args){ + if(args.length != 1){ + System.err.println("Usage: LetterGrade "); + return; + } + int score = Integer.parseInt(args[0]); + + if(score <= 100){ + System.out.println("A"); + } + else if(score <= 80){ + System.out.println("B"); + } + else if(score <= 60){ + System.out.println("C"); + } + else if(score <= 40){ + System.out.println("D"); + } + else if(score <= 20){ + System.out.println("E"); + } + else if(score <= 0){ + System.out.println("Drop Out"); + } + else{ + System.out.println("Interval Nilai 0 - 100"); + } + + } +} \ No newline at end of file