Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Calculator {
- private int first;
- private int second;
- public Calculator(int first, int second) {
- this.first = first;
- this.second = second;
- }
- public static void main(String[] args) {
- System.out.println("chose operation");
- System.out.println("1-plus");
- System.out.println("2-minus");
- Scanner scanner = new Scanner(System.in);
- int operation = scanner.nextInt();
- System.out.println("enter number 1");
- int first = scanner.nextInt();
- System.out.println("enter number 2");
- int second = scanner.nextInt();
- Calculator calc = new Calculator(first, second);
- if (operation ==1) {
- System.out.println(calc.plus());
- }
- else if(operation==2){
- System.out.println(calc.minus());
- }
- }
- public int plus(){
- return first+second;
- }
- public int minus(){
- return first-second;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement