import javax.swing.JOptionPane;//biar bisa JOptionPane
public class Kalkulator {
public static void main(String[] args) {
int nilai1, nilai2, hasil;
int pilih;
while(true){
pilih = Integer.parseInt(JOptionPane.showInputDialog("1.Penjumlahan \n2.Perkalian\n3.Pengurangan \n4.Pembagian \n5.Exit"));
switch(pilih){
case 1 :
JOptionPane.showMessageDialog(null,"--Penjumlahan Sederhana--");
nilai1=Integer.parseInt(JOptionPane.showInputDialog("Nilai 1"))
nilai2=Integer.parseInt(JOptionPane.showInputDialog("Nilai 2"));
hasil=nilai1+nilai2;
JOptionPane.showMessageDialog(null,nilai1 +" + "+ nilai2+" = " +hasil);break;
case 2 :
JOptionPane.showMessageDialog(null,"--Perkalian Sederhana--");
nilai1=Integer.parseInt(JOptionPane.showInputDialog("Nilai 1"));
nilai2=Integer.parseInt(JOptionPane.showInputDialog("Nilai 2"));
hasil=nilai1*nilai2;
JOptionPane.showMessageDialog(null,nilai1 +" x "+ nilai2+" = " +hasil);break;
case 3 :
JOptionPane.showMessageDialog(null,"--Pengurangan Sederhana--");
nilai1=Integer.parseInt(JOptionPane.showInputDialog("Nilai 1"));
nilai2=Integer.parseInt(JOptionPane.showInputDialog("Nilai 2"));
hasil=nilai1-nilai2;
JOptionPane.showMessageDialog(null,nilai1 +" - "+ nilai2+" = " +hasil);break;
case 4 :
JOptionPane.showMessageDialog(null,"--Peembagian Sederhana--");
nilai1=Integer.parseInt(JOptionPane.showInputDialog("Nilai 1"));
nilai2=Integer.parseInt(JOptionPane.showInputDialog("Nilai 2"));
hasil=nilai1/nilai2;
JOptionPane.showMessageDialog(null,nilai1 +" : "+ nilai2+" = " +hasil);break;
case 5:
System.exit(0);
}
}
}
}
Kamis, 19 Juli 2012
SWITCH dan CASE pada JAVA
Publish By BATCH 6 SEAMOLEC 2012 → 03.30
Kategory → SWITCH dan CASE pada JAVA » JAVA , SEAMOLEC » BLOG BATCH 6 SEAMOLEC
Langganan:
Posting Komentar (Atom)
Mantab broooo....
BalasHapus