if-else
import java.util.Scanner; // Import java untuk fungsi meminta inputan user
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner (System.in); // kita masukan fungsi abstract Scanner kedalam sebuah object yang bernama in
int point;
System.out.print("Masukan Jumlah Point =");
point = in.nextInt(); // untuk meminta inputan berupa angka bisa menggunakan in.nextInt();
System.out.println("-----------------------");
System.out.println("Nama : Driyanto Saputro");
System.out.println("point : " + point);
if (point==3)
System.out.println("Medali Emas");
else if (point==2)
System.out.println("Medali Perak");
else if (point==1)
System.out.println("Medali Perunggu");
else
System.out.println("Tidak mendapat Medali");
System.out.println("-----------------------");
}
}
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner (System.in); // kita masukan fungsi abstract Scanner kedalam sebuah object yang bernama in
int point;
System.out.print("Masukan Jumlah Point =");
point = in.nextInt(); // untuk meminta inputan berupa angka bisa menggunakan in.nextInt();
System.out.println("-----------------------");
System.out.println("Nama : Driyanto Saputro");
System.out.println("point : " + point);
if (point==3)
System.out.println("Medali Emas");
else if (point==2)
System.out.println("Medali Perak");
else if (point==1)
System.out.println("Medali Perunggu");
else
System.out.println("Tidak mendapat Medali");
System.out.println("-----------------------");
}
}
switch-case
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner masuk = new Scanner (System.in);
int point;
System.out.print("Masukan Jumlah Point =");
point = masuk.nextInt();
System.out.println("-----------------------");
System.out.println("Nama : Driyanto Saputro");
System.out.println("point : " + point);
switch (point)
{
case 3 :
System.out.println("Medali Emas");
break;
case 2 :
System.out.println("Medali Perak");
break;
case 1:
System.out.println("Medali Perunggu");
break;
default:
System.out.println("Tidak mendapat Medali");
}
System.out.println("-----------------------");
}
}
public class Main
{
public static void main(String[] args)
{
Scanner masuk = new Scanner (System.in);
int point;
System.out.print("Masukan Jumlah Point =");
point = masuk.nextInt();
System.out.println("-----------------------");
System.out.println("Nama : Driyanto Saputro");
System.out.println("point : " + point);
switch (point)
{
case 3 :
System.out.println("Medali Emas");
break;
case 2 :
System.out.println("Medali Perak");
break;
case 1:
System.out.println("Medali Perunggu");
break;
default:
System.out.println("Tidak mendapat Medali");
}
System.out.println("-----------------------");
}
}
Hasil dari program diatas bisa kita lihat pada gambar di bawah ini.
0 komentar:
Posting Komentar