Skip to content
42 changes: 42 additions & 0 deletions bubblesort.java
Original file line number Diff line number Diff line change
@@ -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;i<n;i++){
for(int j=1;j<(n-i);j++){
if(arrayInteger[j-1]>arrayInteger[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<arrayInteger.length; i++){
System.out.print(arrayInteger[i] + " ");
}


}
}
50 changes: 50 additions & 0 deletions bulan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
public class bulan{
public static void main(String[] args){
if(args.length!=1){
System.err.println("Usage: bulan <nomorbulan>");
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");
}
}
}
19 changes: 19 additions & 0 deletions faktorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class faktorial{
public static void main(String[] args){
if(args.length!=1){
System.err.println("Usage: faktorial <angka>");
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);



}
}
41 changes: 41 additions & 0 deletions jlh_hari.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
public class jlh_hari{
public static void main(String[] args){
if(args.length!=2){
System.err.println("Usage: jlh_hari <bulan> <tahun>");
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");
}

}
}
19 changes: 19 additions & 0 deletions recfaktorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class recfaktorial{
public static void main(String[] args){
if(args.length!=1){
System.err.println("Usage: recfaktorial <angka>");
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));
}
}
}
32 changes: 32 additions & 0 deletions score.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class score{
public static void main(String[] args){
if(args.length != 1){
System.err.println("Usage: LetterGrade <numeric-number>");
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");
}

}
}