From 19d533a7d1ed12780b89469b46a2f5e2f07d78f4 Mon Sep 17 00:00:00 2001 From: Priagung Satyagama Date: Tue, 14 Aug 2018 10:55:32 +0700 Subject: [PATCH 1/2] initial commit, added recursive factorial --- Calender.java | 36 ++++++++++++++++++++++++++++++++++ FactRecursive.java | 18 +++++++++++++++++ Factorial.java | 18 +++++++++++++++++ HelloWorld.java | 5 +++++ Scoring.java | 17 ++++++++++++++++ SumHari.java | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+) create mode 100644 Calender.java create mode 100644 FactRecursive.java create mode 100644 Factorial.java create mode 100644 HelloWorld.java create mode 100644 Scoring.java create mode 100644 SumHari.java diff --git a/Calender.java b/Calender.java new file mode 100644 index 0000000..6ad0d5f --- /dev/null +++ b/Calender.java @@ -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; + } + } +} \ No newline at end of file diff --git a/FactRecursive.java b/FactRecursive.java new file mode 100644 index 0000000..e89338b --- /dev/null +++ b/FactRecursive.java @@ -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]))); + } + } +} \ No newline at end of file diff --git a/Factorial.java b/Factorial.java new file mode 100644 index 0000000..7fcece6 --- /dev/null +++ b/Factorial.java @@ -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]))); + } + } +} \ No newline at end of file diff --git a/HelloWorld.java b/HelloWorld.java new file mode 100644 index 0000000..8b20ecc --- /dev/null +++ b/HelloWorld.java @@ -0,0 +1,5 @@ +public class HelloWorld { + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} \ No newline at end of file diff --git a/Scoring.java b/Scoring.java new file mode 100644 index 0000000..ad4f4f2 --- /dev/null +++ b/Scoring.java @@ -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"); + } + } +} \ No newline at end of file diff --git a/SumHari.java b/SumHari.java new file mode 100644 index 0000000..d9124ba --- /dev/null +++ b/SumHari.java @@ -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!"); + } + } +} \ No newline at end of file From 2c05fdba135336a17d75f4dc1503faeecc47874c Mon Sep 17 00:00:00 2001 From: Priagung Satyagama Date: Tue, 14 Aug 2018 11:35:06 +0700 Subject: [PATCH 2/2] added bubblesort --- .gitignore | 1 + BubbleSort.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .gitignore create mode 100644 BubbleSort.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/BubbleSort.java b/BubbleSort.java new file mode 100644 index 0000000..faf8b24 --- /dev/null +++ b/BubbleSort.java @@ -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(); + } + } +} \ No newline at end of file