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

Resha - Java #11

Open
wants to merge 4 commits 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
27 changes: 27 additions & 0 deletions BubbleSortAsc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.Arrays;

public class BubbleSortAsc{
public static void main(String[] args) {
int[] angka = new int[args.length];

for(int i=0;i<args.length;i++){
angka[i] = Integer.parseInt(args[i]);
}
for(int i=0;i<args.length;i++) {
for(int j=0;j<args.length-1;j++) {
if(angka[j] > angka[j+1]){
//swap 2 variabel
angka[j] = angka[j]+angka[j+1];
angka[j+1] = angka[j]-angka[j+1];
angka[j] = angka[j]-angka[j+1];

//swap 3 variabel
/* int temp = angka[j];
angka[j] = angka[j+1];
angka[j+1] = temp;*/
}
}
}
System.out.println("Hasil : "+Arrays.toString(angka));
}
}
68 changes: 68 additions & 0 deletions Days.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
public class Days{
public static void main(String[] args) {
int bln = Integer.parseInt(System.console().readLine());
int thn = Integer.parseInt(System.console().readLine());
switch(thn%400){
case 0: {
switch(bln){
case 2: System.out.println("29 hari"); break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: System.out.println("31 hari"); break;
default: System.out.println("30 hari"); break;
}
} break;
default: {
switch(thn%100){
case 0: {
switch(bln){
case 2: System.out.println("28 hari"); break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: System.out.println("31 hari"); break;
default: System.out.println("30 hari"); break;
}
} break;
default: {
switch(thn%4){
case 0: {
switch(bln){
case 2: System.out.println("29 hari"); break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: System.out.println("31 hari"); break;
default: System.out.println("30 hari"); break;
}
} break;
default : {
switch(bln){
case 2: System.out.println("28 hari"); break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: System.out.println("31 hari"); break;
default: System.out.println("30 hari"); break;
}
}break;
}
} break;
}
} break;
}
}
}
10 changes: 10 additions & 0 deletions Faktorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Faktorial{
public static void main(String[] args) {
int input = Integer.parseInt(args[0]);
int cpy = input;
for (int i=1;i<cpy;i++){
input = input*i;
}
System.out.println(input);
}
}
13 changes: 13 additions & 0 deletions FaktorialRksf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class FaktorialRksf{
public static void main(String[] args) {
int input = Integer.parseInt(args[0]);
System.out.println(factorial(input));
}
public static int factorial(int n){
if(n==1)
return 1;
else{
return n*factorial(n-1);
}
}
}
24 changes: 24 additions & 0 deletions HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class HelloWorld{
public static void main(String[] args) {
int input = Integer.parseInt(args[0]);
// int input = Integer.parseInt(System.console().readLine());
if(input>=1&&input<=20){
System.out.println("Nilai E");
}
else if(input>=21&&input<=40){
System.out.println("Nilai D");
}
else if(input>=41&&input<=60){
System.out.println("Nilai C");
}
else if(input>=61&&input<=80){
System.out.println("Nilai B");
}
else if(input>=81&&input<=10){
System.out.println("Nilai A");
}
else{
System.out.println("Input angka 1-100");
}
}
}
21 changes: 21 additions & 0 deletions Months.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Months{
public static void main(String[] args) {
int input = Integer.parseInt(args[0]);
// int input = Integer.parseInt(System.console().readLine());
switch(input){
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("Input 1-12!"); break;
}
}
}