Pangil_aku_Andi

Don't Give Up in Life …

Program Switch Case


import java.util.*;
public class switch1
{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
int bil1,bil2,pilihan;
int perkalian,penambahan,pengurangan;
float pembagian;
System.out.println(” ARITMATIKA\n”);
System.out.print(” Masukan Bil.1 :”); bil1 = input.nextInt();
System.out.print(” Masukan Bil.2 :”); bil2 = input.nextInt();
System.out.println(“\n”);
System.out.println(” Pilihan :”);
System.out.println(” ————–“);
System.out.println(” 1. Perkalian”);
System.out.println(” 2. Pembagian”);
System.out.println(” 3. Penambahan”);
System.out.println(” 4. Pengurangan”);
System.out.println(” ————–\n”);
System.out.print(” Pilihan Anda :”);
pilihan = input.nextInt();
switch(pilihan){
case 1:
perkalian=bil1*bil2;
System.out.println(” “+bil1+” * “+bil2+” =”);
System.out.println(” Perkalian 2 bilangan tersebut adalah :”+perkalian);
break;
case 2:
pembagian=(float)bil1/bil2;
System.out.println(” “+bil1+” / “+bil2+” =”);
System.out.println(” Pembagian 2 bilangan tersebut adalah :”+pembagian);
break;
case 3:
penambahan=bil1+bil2;
System.out.println(” “+bil1+” + “+bil2+” =”);
System.out.println(” Penambahan 2 bilangan tersebut adalah :”+penambahan);
break;
case 4:
pengurangan=bil1-bil2;
System.out.println(” “+bil1+” – “+bil2+” =”);
System.out.println(” Pengurangan 2 bilangan tersebut adalah :”+pengurangan);
break;
}
}
}
save as dengan “switch1.java”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: