0% found this document useful (0 votes)
160 views4 pages

B. PERFORMANCE TASK - Simple Calculator

This Java code uses a scanner to prompt a user to enter an arithmetic operator and two numbers, then performs the calculation on those numbers based on the operator entered and prints the result. It supports addition, subtraction, multiplication, division, and modulus operations on two integers input by the user.

Uploaded by

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

B. PERFORMANCE TASK - Simple Calculator

This Java code uses a scanner to prompt a user to enter an arithmetic operator and two numbers, then performs the calculation on those numbers based on the operator entered and prints the result. It supports addition, subtraction, multiplication, division, and modulus operations on two integers input by the user.

Uploaded by

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

import java.util.

Scanner;

public class Main

public static void main(String[] args) {

char operation;

int num1, num2, sum, difference, product, quotient, modulus;

Scanner sc = new Scanner(System.in);

System.out.println("Enter an Operation: (Choose between +, -, *, /, %)");

operation = sc.next().charAt(0);

System.out.print("Enter 1st number: ");

num1 = sc.nextInt();

System.out.print("Enter 2nd number: ");

num2 = sc.nextInt();

if(operation == '+'){

sum = num1 + num2;

System.out.print("The sum is: " + sum);

else if(operation == '-'){

difference = num1 - num2;

System.out.print("The difference is: " + difference);

}
else if(operation == '*'){

product = num1 * num2;

System.out.print("The product is: " + product);

else if(operation == '/'){

quotient = num1 / num2;

System.out.print("The quotient is: " + quotient);

else if(operation == '%'){

modulus = num1 % num2;

System.out.print("The modulus is: " + modulus);

You might also like