You are on page 1of 1

//Source Code

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the first int: ");
int first = Integer.valueOf(input.nextLine());
System.out.print("Enter the second int: ");
int second = Integer.valueOf(input.nextLine());
System.out.print("Enter +, -, or *: ");
String op = input.nextLine();
int result = calculate(first, second, op);
System.out.println(first + " " + op + " " + second + " = " + result);

}
public static int calculate(int a, int b, String op){
switch(op){
case "+":return a+b;
case "-":return a-b;
case "*":return a*b;
}
System.out.println("Operation not supported.");
return 0;
}
}
//Output
//Trial 1
Enter the first int: 3
Enter the second int: 4
Enter +, -, or *: +
3 + 4 = 7
//Trial 2
Enter the first int: 2
Enter the second int: 10
Enter +, -, or *: -
2 - 10 = -8
//Trial 3
Enter the first int: 3
Enter the second int: 6
Enter +, -, or *: *
3 * 6 = 18

You might also like