Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int numberOne = Integer.parseInt(scanner.nextLine());
- int numberTwo = Integer.parseInt(scanner.nextLine());
- String operator = scanner.nextLine();
- int result = 0;
- switch (operator) {
- case "+":
- result = numberOne + numberTwo;
- break;
- case "-":
- result = numberOne - numberTwo;
- break;
- case "/":
- result = numberOne / numberTwo;
- break;
- case "*":
- result = numberOne * numberTwo;
- break;
- case "%":
- result = numberOne % numberTwo;
- break;
- }
- // This is the way the code should be changed in order to work - notice that you had missed the spaces in the message:
- // So instead of printing let's say 5+4=9, it should be 5 + 4 = 9
- System.out.println(numberOne + " " + operator + " " + numberTwo + " = " + result);
- // Also, here's a better way to do the same thing, using placeholders:
- // System.out.printf("%d %s %d = %d", numberOne,operator,numberTwo,result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement