casper. Powered by Blogger.

Blog ini bertujuan untuk share ilmu dan pengetahuan. Semua source/aplikasi di blog ini bebas disebar dan mencamtumkan sumber "fandy-alfa.blogspot.com".

RSS

PROGRAM Kalkulator Sederhana

import java.io.*;

public class project1 {
  
    public static void main(String[] args) throws IOException
    {       
         double hasil;
        
         System.out.println("PROGRAM KALKULATOR SEDERHANA");
        System.out.println("============================");
       
        BufferedReader stdin =
            new BufferedReader (new InputStreamReader(System.in));
       
        System.out.print("Masukkan nilai pertama : ");
        double x = Double.parseDouble(stdin.readLine());
       
        System.out.print("Masukkan nilai kedua   : ");
        double y = Double.parseDouble(stdin.readLine());
        System.out.println("");
        System.out.println("OPERATOR");
        System.out.println("1. Penjumlahan");
        System.out.println("2. Pengurangan");
        System.out.println("3. Perkalian");
        System.out.println("4. Pembagian");
        System.out.print("Masukkan pilihan : ");
        int pilih = Integer.parseInt(stdin.readLine());
       
        if (pilih==1)
        {
            hasil=x+y;
            System.out.println(x + " + " + y + " = " + hasil);               
        }
       
        if (pilih==2)
        {
            hasil=x-y;
            System.out.println(x + " - " + y + " = " + hasil);               
        }
       
        if (pilih==3)
        {
            hasil=x*y;
            System.out.println(x + " * " + y + " = " + hasil);               
        }           
       
        if (pilih==4)
        {
            hasil=x/y;
            System.out.println(x + " / " + y + " = " + hasil);               
        }
    }
}
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comments:

Post a Comment