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

NicoPanjaitan_Java1 #28

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
35 changes: 35 additions & 0 deletions BubbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Nama File : BubbleSort.java
Nico G. S. Panjaitan
*/

public class BubbleSort {

public static void main (String[] args) {

if (args.length < 1) {
System.err.println ("Usage:Input form <al1, al2, ...,>");
return;
}

int list[] = new int [args.length];

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

for(int i=0; i<list.length; i++){
for(int j=i + 1; j<list.length; j++){
if(list[i] > list[j]){
int temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}

System.out.print("Hasil setelah Bubble Sort: ");
for(int i=0; i<list.length; i++){
System.out.print(list[i] + " " );
}
}
}
57 changes: 57 additions & 0 deletions Calender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Nama File : Calender.java
Nico G. S. Panjaitan
*/

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

if (args.length != 1) {
System.out.println ("Usage:Month form number <month>");
return;
}

int month = Integer.parseInt(args[0]);
switch (month) {
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("Masukkan angka pilihan <bulan> 1-12");

}
}

}
50 changes: 50 additions & 0 deletions Calender2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Nama File : Calender2.java
Nico G. S. Panjaitan
*/

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

if (args.length != 2) {
System.out.println ("Usage:Month form number <month>");
return;
}

int month = Integer.parseInt(args[0]);
int year = Integer.parseInt (args[1]);


switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println (31);
break;

case 2:
if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0 ))
{
System.out.println (29);
}
else
System.out.println (28);
break;

case 4:
case 6:
case 9:
case 11:
System.out.println (30);
break;

default :
System.out.println("Masukkan angka pilihan <bulan> 1-12");

}
}

}
23 changes: 23 additions & 0 deletions FactorRek.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Nama File : FactorRek.java
Nico G. S. Panjaitan
*/

public class FactorRek {
public static int factorial (int angka) {
if (angka == 0)
return 1;
else
return (angka * factorial(angka-1));
}

public static void main (String[] args) {
if (args.length != 1) {
System.out.println ("Usage:Input form <number>");
return;
}

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

System.out.println("Factorial dari " + angka + " adalah " + factorial(angka));
}
}
20 changes: 20 additions & 0 deletions Factorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Nama File : Factorial.java
Nico G. S. Panjaitan
*/

public class Factorial {
public static void main (String[] args) {
if (args.length != 1) {
System.out.println ("Usage: factorial form <number>");
return;
}
int fak = 1;
int angka = Integer.parseInt (args[0]);

for(int i=1; i<=angka; i++){
fak = fak * i;
}

System.out.println("Faktorialnya "+angka+" adalah "+fak);
}
}
34 changes: 34 additions & 0 deletions Score.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Nama File : Score.java
Nico G. S. Panjaitan
*/

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

if (args.length != 1) {
System.out.println ("Usage:Score form-number <month>");
return;
}

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

if( score < 30) {
System.out.println("E");
}
else if( score < 40) {
System.out.println("D");
}
else if( score < 50) {
System.out.println("C");
}
else if( score < 60) {
System.out.println("B");
}
else if( score < 70) {
System.out.println("AB");
}
else {
System.out.println("A");
}
}
}