Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaCalculator;
- import java.util.Scanner;
- public class Calculator {
- public static void main (String [] args) {
- System.out.println("Please enter your first number");
- Scanner Scanner1 = new Scanner (System.in);
- int firstInteger = Scanner1.nextInt();
- System.out.println("Please enter your second number");
- Scanner Scanner2 = new Scanner (System.in);
- int secondInteger = Scanner2.nextInt();
- System.out.println("Please enter the operation");
- Scanner Scanner3 = new Scanner (System.in);
- String userOperation = Scanner3.next();
- String additionOperation = "+";
- String subtractionOperation = "-";
- String multiplacationOperation = "*";
- String divisionOperation = "/";
- boolean addition = userOperation.equals(additionOperation);
- boolean subtract = userOperation.equals(subtractionOperation);
- boolean multiplacation = userOperation.equals(multiplacationOperation);
- boolean division = userOperation.equals(divisionOperation);
- int answer = 0;
- if (addition){
- answer = (firstInteger+secondInteger);
- System.out.print(answer);
- }else{
- if (subtract) {
- answer = (firstInteger-secondInteger);
- System.out.print(answer);
- }else{
- if (multiplacation) {
- answer = (firstInteger*secondInteger);
- System.out.print(answer);
- }else{
- if (division) {
- answer = (firstInteger/secondInteger);
- }else{
- System.out.print(answer);
- }
- Scanner1.close();
- Scanner2.close();
- Scanner3.close();
- }
- }}}}
Advertisement
Add Comment
Please, Sign In to add comment