Saturday, February 23, 2013

simple calculator


Simple Calculator: Addition, Subtraction and Multiplication





/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication6;

/**
 *
 * @author Administrator
 */
import java.util.Scanner;
public class Main {
    public static void main(String args[]){
        Scanner input=new Scanner(System.in);

        int g;
        int f;
                int h;
                String a;
                char d;

        System.out.println("    MENU    ");
       
        System.out.println("1 - ADDITION " +
                         "\n2 - SUBTRATION " +
                         "\n3 - MULTIPLICATION " );
               
               
                System.out.print("Choose a number: "  );
                g = input.nextInt();

                System.out.println("Enter the first number: " );
                f = input.nextInt();


                System.out.println("Enter the second number: "  );
                 h = input.nextInt();

               System.out.println("Enter a symble: "  );
                 d= input.next().charAt(0);


                
                 if(d=='+')
                     System.out.println(f+h);
                  else if(d == '-')
                     System.out.println(f-h);
                 else if (d == '*')
                     System.out.println(f*h);
                

                System.out.println("Do you want to continue press Y/N: ");
                d= input.next().charAt(0);
               
                switch(d){
                    case 'Y': System.out.println(d);
                       
                        case 'N':  System.out.println(d);
                }




                


    }


}

No comments:

Post a Comment