0% found this document useful (0 votes)
285 views2 pages

Calculator Java

This Java program defines a calculator class with a main method that takes in three integers - a, b, and s. It uses s to determine which mathematical operation to perform on a and b using a switch statement - addition, subtraction, multiplication, or division. It then prints out the result of the calculation. If an invalid option is selected, it prints an error message.

Uploaded by

AryanKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
285 views2 pages

Calculator Java

This Java program defines a calculator class with a main method that takes in three integers - a, b, and s. It uses s to determine which mathematical operation to perform on a and b using a switch statement - addition, subtraction, multiplication, or division. It then prints out the result of the calculation. If an invalid option is selected, it prints an error message.

Uploaded by

AryanKumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

class calculator

{

public static void main(int a,int b,int s)
{
int c;

System.out.println("Enter 1 for Addition");
System.out.println("Enter 2 for Subtraction");

System.out.println("Enter 3 for Multiplication");

System.out.println("Enter 4 for Division");

switch(s)

{

case 1:
c=a+b;

System.out.println("ReSult:"+c);

break;

case 2:

c=a-b;

System.out.println("ReSult:"+c);
break;

case 3:

c=a*b;

System.out.println("ReSult:"+c);

break;

case 4:
c=a/b;
System.out.println("ReSult:"+c);
break;

default:
System.out.println("Invalid option");

}
}
}

You might also like