Pages

Subscribe:

Senin, 07 Oktober 2013

Program Java Kalkulator Sederhana

   public static void main(String[] args) {
        // TODO code application logic here
        /* 1. Header Program */
        System.out.println("*************************************");
        System.out.println("Program Kalkulator");
        System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
       
        /* 2. Variabel/Simbol */

        double bil_1;
        double bil_2;
        String jenis_opr;
        double hasil = 0;

       
        Scanner in = new Scanner (System.in);
        /* 3. Output dan input user */
        System.out.println("Masukkan bilangan I\t:");
        bil_1 = in.nextDouble();
        System.out.println("Masukkan bilangan II\t:");
        bil_2 = in.nextDouble();
        System.out.println("Masukkan jenis operasi\t:");
        jenis_opr = in.next();
       
        /* 4. Proses Perhitungan */
        if ("+".equals(jenis_opr)){
            hasil = (bil_1+bil_2);
        } else if ("-".equals (jenis_opr)){
            hasil = (bil_1-bil_2);
        } else if ("*".equals (jenis_opr)){
            hasil = (bil_1*bil_2);
        } else if ("/".equals (jenis_opr)){
            hasil = (bil_1/bil_2);
        }
     
        /* 5. Output hasil */
        System.out.println("Hasil Perhitungan = " + hasil);
       

       
        /* 6. Footer Program */
        System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
        System.out.println("copyright by Zulianur K.");
        System.out.println("*************************************");
    }
}

0 komentar:

Posting Komentar