Skip to content

Instantly share code, notes, and snippets.

@rokon12
Created February 18, 2020 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rokon12/4cafec88e9193b6d3744325f2fc3753d to your computer and use it in GitHub Desktop.
Save rokon12/4cafec88e9193b6d3744325f2fc3753d to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scr = new Scanner(System.in);
Calculator calculator = new Calculator();
System.out.println("Enter first input: ");
int a = scr.nextInt();
System.out.println("Enter second input: ");
int b = scr.nextInt();
System.out.println(" Choose your options: \n" +
"1 for addition\n" +
"2 for subtraction\n" +
"3 for multiplication\n" +
"4 for division\n" +
"");
int option = scr.nextInt();
if (option == 1) {
int result = calculator.add(a, b);
System.out.println("Result: " + result);
}
if (option == 2) {
}
}
}
@ahfayej08
Copy link

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    Scanner scr = new Scanner(System.in);
    Calculator calculator = new Calculator();

    System.out.println("Enter first input: ");
    int a = scr.nextInt();

    System.out.println("Enter second input: ");
    int b = scr.nextInt();

    System.out.println(" Choose your options: \n" +
                               "1 for addition\n" +
                               "2 for subtraction\n" +
                               "3 for multiplication\n" +
                               "4 for division\n" +
                               "");

    int option = scr.nextInt();

    if (option == 1) {
        int result = calculator.add(a, b);
        System.out.println("Result: " + result);
    }

    if (option == 2) {
    	double result = calculator.subtract(a, b);
    	System.out.println("Result: " + result);

    }
    
    if (option == 3) {
		double result = calculator.multiply(a, b);
		System.out.println("Result: " + result);
	}
    
    if (option == 4) {
    	double result = calculator.div(a, b); 
    	System.out.println("Result: " + result);
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment