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

PR from priagungs #13

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.class
31 changes: 31 additions & 0 deletions BubbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class BubbleSort {
private static Integer[] sort(Integer[] input) {
for (int i = 0; i < input.length; i++) {
for (int j = i; j < input.length; j++) {
if (input[i] > input[j]) {
Integer temp = input[i];
input[i] = input[j];
input[j] = temp;
}
}
}
return input;
}

public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Invalid input");
}
else {
Integer[] input = new Integer[args.length];
for (int i = 0; i < args.length; i++) {
input[i] = Integer.parseInt(args[i]);
}
input = sort(input);
for (Integer el : input) {
System.out.print(el + " ");
}
System.out.println();
}
}
}
36 changes: 36 additions & 0 deletions Calender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
public class Calender {
public static void main(String[] args) {
Integer i = null;
if (args.length > 0) {
i = Integer.parseInt(args[0]);
}
switch (i) {
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("Wrong input"); break;
}
}
}
18 changes: 18 additions & 0 deletions FactRecursive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class FactRecursive {
private static int fact(int input) {
if (input == 0 || input == 1) {
return 1;
}
else {
return input*fact(input-1);
}
}
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Error Input!");
}
else {
System.out.println(fact(Integer.parseInt(args[0])));
}
}
}
18 changes: 18 additions & 0 deletions Factorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Factorial {
private static Integer fact (Integer input) {
Integer temp = 1;
for (int i = 1; i <= input; i++) {
temp *= i;
}
return temp;
}

public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Error Input!");
}
else {
System.out.println(fact(Integer.parseInt(args[0])));
}
}
}
5 changes: 5 additions & 0 deletions HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
17 changes: 17 additions & 0 deletions Scoring.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Scoring {
public static void main(String[] args) {
Integer score = null;
if (args.length > 0) {
score = Integer.parseInt(args[0]);
}
if (score > 80) {
System.out.println("A");
}
else if (score > 50) {
System.out.println("B");
}
else {
System.out.println("E");
}
}
}
49 changes: 49 additions & 0 deletions SumHari.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
public class SumHari {
private static Integer jumlahHari (Integer tahun, Integer bulan) {
if (bulan > 12 || bulan < 0) {
return -1;
}
switch (bulan) {
case 1:
return 31;
case 2:
if (tahun % 4 == 0) {
return 29;
}
else {
return 28;
}
case 3:
return 31;
case 4:
return 30;
case 5:
return 31;
case 6:
return 30;
case 7:
return 31;
case 8:
return 31;
case 9:
return 30;
case 10:
return 31;
case 11:
return 30;
case 12:
return 31;
default:
return -1;
}
}

public static void main(String[] args) {
if (args.length == 2) {
System.out.println(jumlahHari(Integer.parseInt(args[0]), Integer.parseInt(args[1])));
}
else {
System.out.println("Wrong input!");
}
}
}