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

Training Java Sesi 1 ~ Abdi Aruan #2

Open
wants to merge 3 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
Binary file added fakrekursif.class
Binary file not shown.
16 changes: 16 additions & 0 deletions fakrekursif.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class fakrekursif{

public static int faktorial(int n){
if(n==1)
return 1;
else
return (n * faktorial(n-1));

}

public static void main(String[] args)
{
int value = Integer.parseInt(args[0]);
System.out.println(faktorial(value));
}
}
Binary file added faktorial.class
Binary file not shown.
14 changes: 14 additions & 0 deletions faktorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class faktorial
{
public static void main(String[] args)
{
int value = Integer.parseInt(args[0]);
int i =1;
int res=1;
for(i=1;i<=value;i++)
{
res *= i;
}
System.out.println(res);
}
}
Binary file added hw.class
Binary file not shown.
35 changes: 35 additions & 0 deletions hw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//Abdi Elman D. A.
//import java.util.*;

public class hw{
public static void main(String[] args){
//Scanner scaner = new Scanner(System.in);
if(args.length != 1){
System.out.println("----");
}
//int score = scaner.nextInt();
int score = Integer.parseInt(args[0]);
String grade;
if(score<=20)
{
grade = "E";
}
else if(score > 20 && score <= 40)
{
grade = "D";
}
else if(score >40 && score <= 60)
{
grade = "C";
}
else if(score >60 && score <=80)
{
grade = "B";
}
else{
grade = "A";
}

System.out.println(grade);
}
}
Binary file added sort.class
Binary file not shown.
29 changes: 29 additions & 0 deletions sort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class sort{
public static void main(String[] args)
{
int len = args.length;
int[] arr;
arr = new int[len];
for(int i=0; i<len;i++)
{
arr[i] = Integer.parseInt(args[i]);
}
for(int i=0;i<len;i++)
{
int temp = 0;
for(int j=0;j<len;j++)
{
if(arr[i] > arr[j]){
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

for(int i=0; i<len;i++)
{
System.out.print(arr[i]+" ");
}
}
}
Binary file added switch1.class
Binary file not shown.
41 changes: 41 additions & 0 deletions switch1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

public class switch1
{
public static void main(String[] args){
if(args.length != 1){
System.out.println("----");
}
int m = Integer.parseInt(args[0]);
String bulan;
switch(m)
{
case 1 : bulan = "Januari";
break;
case 2 : bulan = "Februari";
break;
case 3 : bulan = "Maret";
break;
case 4 : bulan = "April";
break;
case 5 : bulan = "Mei";
break;
case 6 : bulan = "Juni";
break;
case 7 : bulan = "Juli";
break;
case 8 : bulan = "Agustus";
break;
case 9 : bulan = "September";
break;
case 10 : bulan = "Oktober";
break;
case 11 : bulan = "November";
break;
case 12 : bulan = "Desember";
break;
default : bulan = "Tidak Ada";
break;
}
System.out.println(bulan);
}
}
Binary file added switch2.class
Binary file not shown.
43 changes: 43 additions & 0 deletions switch2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
public class switch2{
public static void main(String[] args){
if(args.length < 1){
System.out.println("----");
}
int tahun = Integer.parseInt(args[0]);
int bulan = Integer.parseInt(args[1]);
int day=0;
switch(bulan){
case 1 : day = 31;
break;
case 2 : if(tahun%4 == 0)
day = 29;
else
day = 28;
break;
case 3 : day = 31;
break;
case 4 : day = 30;
break;
case 5 : day = 31;
break;
case 6 : day = 30;
break;
case 7 : day = 31;
break;
case 8 : day = 31;
break;
case 9 : day = 30;
break;
case 10 : day = 31;
break;
case 11 : day = 30;
break;
case 12 : day = 31;
break;
default : System.out.println("Tidak Ada");
break;
}
System.out.println(day);
}

}