Selasa, 06 Maret 2012

kalkulator.java

/*
nama file : Kalkulator.java
programer : elekomfireball.blogspot.com
deskripsi :
 -input nilai 1
 -input nilai 2
 -cari jumlah.kurang,kali dan bagi
 -tampilkan hasilnya
*/
import javax.swing.JOptionPane;
class Kalkulator 
{
 public static void main(String[] args) 
 {
  //variabel
  String nilai1String;
  String nilai2String;

  int nilai1;
  int nilai2;
  int jumlah;
  int kurang;
  int kali;
  double bagi;

  nilai1String = JOptionPane.showInputDialog("Masukkan Nilai l : ");
  nilai1 = Integer.parseInt(nilai1String);

  nilai2String = JOptionPane.showInputDialog("Masukkan Nilai 2 : ");
  nilai2 = Integer.parseInt(nilai2String);

  jumlah = nilai1 + nilai2;
  kurang = nilai1 - nilai2;
  kali = nilai1 * nilai2;
  bagi = nilai1 / (double) nilai2;

  JOptionPane.showMessageDialog(null, "Hasil Jumlah = " + jumlah + "\nHasil Kurang = "+ kurang +"\nHasil Kali = "+ kali +"\nHasil bagi = "+ bagi);

 }
}