Selasa, 05 Juni 2012

Program java kalkulator sederhana

import java.util.Scanner;

public class SimpleCalc {

    public static void main(String args[]) {
   
        double a, b, c;
   
        Scanner scn = new Scanner(System.in);

        System.out.println("\n1. Add");
        System.out.println("2. Subtract");
        System.out.println("3. Multiply");
        System.out.println("4. Divide\n");
        System.out.print("Please make a selection: ");
        int function = scn.nextInt();
       
        System.out.print("\nA = ");
        a = scn.nextDouble();
        System.out.print("B = ");
        b = scn.nextDouble();
       
        switch(function) {
        case 1:
        c = a + b;
        System.out.println(a + " + " + b + " = " + c);
        break;
        case 2:
        c = a - b;
        System.out.println(a + " - " + b + " = " + c);
        break;
        case 3:
        c = a * b;
        System.out.println(a + " * " + b + " = " + c);
        break;
        case 4:
        c = a / b;
        System.out.println(a + " / " + b + " = " + c);
        break;       
        }
   
    }

}

0 komentar:

Posting Komentar

resep donat empuk ala dunkin donut resep kue cubit coklat enak dan sederhana resep donat kentang empuk lembut dan enak resep es krim goreng coklat kriuk mudah dan sederhana resep es krim coklat lembut resep bolu karamel panggang sarang semut

Copyright © Deja Area | Powered by Blogger

Design by Anders Noren | Blogger Theme by NewBloggerThemes.com | BTheme.net      Up ↑