Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sesi 1 Alvin #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Bubble.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//import java.util.Scanner;

public class Bubble {

public static void main(String[] args){

int[] arr = new int[10];
int tmp = 0;
for (int i=0; i<args.length; i++){
arr[i] = Integer.parseInt(args[i]);
};

for (int i=0; i<args.length-1; i++){
for (int j=i+1; j<args.length; j++){
if (arr[i]>arr[j]){
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
};
};
};

for (int i=0; i<args.length; i++){
System.out.print(arr[i]+" ");
};

}
}
38 changes: 38 additions & 0 deletions BulanTahun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.Scanner;

public class BulanTahun {
public static void main(String[] args){

int bulan = Integer.parseInt(args[0]);
int tahun = Integer.parseInt(args[1]);
int hari = 0;

//Scanner in = new Scanner(System.in);
switch (bulan){
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 :
hari = 31;
break;
case 4 :
case 6 :
case 9 :
case 11 :
hari = 30;
break;
case 2 :
if (((tahun%4==0)&&(tahun%100!=0))||tahun%400==0){
hari = 29;
} else {
hari = 28;
}
break;
}

System.out.println(hari);
}
}
17 changes: 17 additions & 0 deletions Faktorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Scanner;

public class Faktorial {
public static void main(String[] args){

int n = Integer.parseInt(args[0]);

int fak = 1;
//Scanner in = new Scanner(System.in);

for (int i=2; i<=n; i++){
fak*=i;
}

System.out.println(fak);
}
}
23 changes: 23 additions & 0 deletions FaktorialRecursive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;

public class FaktorialRecursive {

public static int fac(int x){

if (x==1) {
return x;
} else {
return x*fac(x-1);
}
}


public static void main(String[] args){

int n = Integer.parseInt(args[0]);

int fak = fac(n);

System.out.println(fak);
}
}
26 changes: 26 additions & 0 deletions Score.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;

public class Score {
public static void main(String[] args){

int score = Integer.parseInt(args[0]);

Scanner in = new Scanner(System.in);

//int score = 100;

//score = in.nextInt();

if (score>80) {
System.out.println("A");
} else if (score>60) {
System.out.println("B");
} else if (score>40) {
System.out.println("C");
} else if (score>20) {
System.out.println("D");
} else {
System.out.println("E");
}
}
}
53 changes: 53 additions & 0 deletions SwitchBulan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.util.Scanner;

public class SwitchBulan {
public static void main(String[] args){

int num = Integer.parseInt(args[0]);

Scanner in = new Scanner(System.in);

String bulan = "tes";

switch (num){
case 1 :
bulan = "Januari";
break;
case 2 :
bulan = "Februari";
break;
case 3 :
bulan = "Maret";
break;
case 4 :
bulan = "April";
break;
case 5 :
bulan = "Mei";
break;
case 6 :
bulan = "Juni";
break;
case 7 :
bulan = "Juli";
break;
case 8 :
bulan = "Agustus";
break;
case 9 :
bulan = "September";
break;
case 10 :
bulan = "Oktober";
break;
case 11 :
bulan = "November";
break;
case 12 :
bulan = "Desember";
break;
}

System.out.println(bulan);
}
}