About Me

header ads

A menu driven arithmetic calculator

//This program is a menu based arithmetic calculator
//which is capable of accepting input from
//user.
import java.util.*;
class calculator
{
public static void main(String Args[])
{
int a;double n1,n2;
double f;
System.out.println("*********************Calculator*********************");
System.out.println("\n\n\n1. Addition\n2. Subtraction\n3. Division\n4. Multiplication\n5. Exit");
System.out.print("\nEnter the serial no. of the operation you would like to perform : ");
Scanner ob=new Scanner(System.in);
a=ob.nextInt();
switch(a)
{
case 1:
    System.out.print("\n\nEnter the first no. : ");
    n1=ob.nextInt();
    System.out.print("Enter the second no. : ");
    n2=ob.nextInt();
    f=n1+n2;
    System.out.println("Final Answer is : "+f);
    break;
case 2:
    System.out.print("\n\nEnter the first no. : ");
    n1=ob.nextInt();
    System.out.print("Enter the second no. : ");
    n2=ob.nextInt();
    f=n1-n2;
    System.out.print("Final Answer is : "+f);
    break;
case 4:
    System.out.print("\n\nEnter the first no. : ");
    n1=ob.nextInt();
    System.out.print("Enter the second no. : ");
    n2=ob.nextInt();
    f=n1*n2;
    System.out.print("The product is : "+f);
    break;
case 3:
    System.out.print("\n\nEnter the first no. : ");
    n1=ob.nextInt();
    System.out.print("Enter the second no. : ");
    n2=ob.nextInt();
    f=n1/n2;
    System.out.print("The Quotient is : "+f);
    break;
case 5:
    break;
default:
    System.out.println("Enter the correct no.");
    break;
}
}
}

Post a Comment

0 Comments