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

HandsOn by Achmad Nasution #16

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 BubbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class BubbleSort {
public static void main(String[] args) {
int[] numbers = new int[args.length];

for(int a = 0; a < args.length; a++) {
numbers[a] = Integer.parseInt(args[a]);
}

bubbleSort(numbers);
for (int number : numbers) {
System.out.print(number + " ");
}
}

public static void bubbleSort(int arr[]) {
int n = arr.length;
int i,j;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
}
46 changes: 46 additions & 0 deletions Bulan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
public class Bulan {
public static void main(String[] args) {
int bulan = Integer.parseInt(args[0]);
switch (bulan) {
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("Bulan Invalid");
break;
}
}
}
54 changes: 54 additions & 0 deletions BulanTahun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
public class BulanTahun {
public static void main(String[] args) {
int bulan = Integer.parseInt(args[0]);
int tahun = Integer.parseInt(args[1]);

switch (bulan) {
case 1 :
System.out.println(31);
break;
case 2 :
if (tahun % 4 == 0 && (tahun % 400 == 0 || tahun % 100 != 0)) {
System.out.println(29);
break;
}
else {
System.out.println(28);
break;
}
case 3 :
System.out.println(31);
break;
case 4 :
System.out.println(30);
break;
case 5 :
System.out.println(31);
break;
case 6 :
System.out.println(30);
break;
case 7 :
System.out.println(31);
break;
case 8 :
System.out.println(31);
break;
case 9 :
System.out.println(30);
break;
case 10 :
System.out.println(31);
break;
case 11 :
System.out.println(30);
break;
case 12 :
System.out.println(31);
break;
default :
System.out.println("Bulan Invalid");
break;
}
}
}
18 changes: 18 additions & 0 deletions Faktorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Faktorial {
public static void main(String[] args) {

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

int jumlah = 1;

if (nilai == 0 && nilai == 1) {
System.out.println(1);
}
else {
for (int i = nilai; i > 0; i--) {
jumlah *= i;
}
System.out.println(jumlah);
}
}
}
18 changes: 18 additions & 0 deletions FungsiFaktorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class FungsiFaktorial {
public static void main(String[] args) {

int nilai = Integer.parseInt(args[0]);
int hasil;
hasil = new FungsiFaktorial().faktorial(nilai);
System.out.println(hasil);
}

public int faktorial(int n) {
if (n == 0) {
return 1;
}
else {
return n * faktorial(n - 1);
}
}
}
23 changes: 23 additions & 0 deletions Score.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Score {
public static void main(String[] args) {
int score = Integer.parseInt(args[0]);
if(score > 80 && score <= 100) {
System.out.println("A");
}
else if(score > 60 && score <= 80) {
System.out.println("B");
}
else if(score > 40 && score <= 60) {
System.out.println("C");
}
else if(score > 20 && score <= 40) {
System.out.println("D");
}
else if(score >= 0 && score <= 20) {
System.out.println("E");
}
else {
System.out.println("Score invalid");
}
}
}