The document describes a Java program that creates a basic four function calculator. The program prompts the user to enter two numbers and select an operator of addition, subtraction, multiplication, or division. It then uses nested if statements to perform the selected arithmetic operation on the numbers and output the result.
1. //Ques. 4 WAP to create equivalent of a four function calculator. The
program requires the user to enter two numbers and an operator. It
then carries out the specified arithmetic operation: addition,
subtraction,multiplication and division of two numbers.(using nested if
statement)
importjava.util.Scanner;
class calculator
{
public static void main(String arr[])
{
inta,b,c,d,e,f,g;
Scanner in = new Scanner(System.in);
System.out.println("Which Operation You wanna Perform");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division n");
c = in.nextInt();
System.out.print("nEnter First Number = ");
a = in.nextInt();
System.out.print("Enter Second Number = ");
b = in.nextInt();
if(c==1)
{
d=a+b;
2. System.out.println("Addition is " +d);
}
else
if(c==2)
{
e=a-b;
System.out.println("Subtraction is " +e);
}
else
if(c==3)
{
f=a*b;
System.out.println("Multiplication is " +f);
}
if(c==4)
{
g=a/b;
System.out.println("Division is " +g);
}
}
}