0% found this document useful (0 votes)
17 views3 pages

Prac1 2

The document describes a practical exercise in Object-Oriented Programming (OOP) where a basic calculator program is implemented in Java. The program allows users to perform addition, subtraction, multiplication, division, and modulo operations based on user input. An example output is provided, demonstrating the functionality of the calculator.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Prac1 2

The document describes a practical exercise in Object-Oriented Programming (OOP) where a basic calculator program is implemented in Java. The program allows users to perform addition, subtraction, multiplication, division, and modulo operations based on user input. An example output is provided, demonstrating the functionality of the calculator.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Subject Name : OOP

Practical 1.2
Definition :- Write a program to implement a basic calculator.
Code:

import java.util.Scanner;
public class Main
{
public static void main(String args[])

{
Scanner intput = new Scanner(System.in);
System.out.println("Enter the value of A:");

int a = intput.nextInt();
System.out.println("Enter the value of B:");
int b = intput.nextInt();

System.out.println("Select A Number \n1:Addition \n2:Subtraction


\n3:Multiplication \n4:Division \n5:Modulo");
int choice = intput.nextInt();

switch (choice)
{
case 1 :
{
System.out.println("Addition:"+(a+b));
break;

}
case 2 :
{

Enrolment No. 230470107069 Page 1


Subject Name : OOP

System.out.println("Subtraction:"+(a-b));
break;

}
case 3 :
{

System.out.println("Multiplication:"+(a*b));
break;
}

case 4 :
{
System.out.println("Division:"+(a/b));

break;
}
case 5 :
{

System.out.println("Modulo:"+(a%b));
break;
}

default :
{
System.out.println("Enter Between 1 to 5...");

}
}
}

Enrolment No. 230470107069 Page 2


Subject Name : OOP

OUTPUT:
Enter the value of A:

5
Enter the value of B:
3

Select A Number
1:Addition
2:Subtraction

3:Multiplication
4:Division
5:Modulo

1
Addition:8

Enrolment No. 230470107069 Page 3

You might also like