Skip to content

Instantly share code, notes, and snippets.

@rokon12
Created February 18, 2020 20:11
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/38c2487b348445885bef8df83a83cbd4 to your computer and use it in GitHub Desktop.
Save rokon12/38c2487b348445885bef8df83a83cbd4 to your computer and use it in GitHub Desktop.
public class Calculator {
public int add(int a, int b) {
return a + b;
}
}
@ahfayej08
Copy link

public class Calculator {

public int add(int a, int b) {
	return a + b;
}
public double subtract(double a, double b) {
	return a - b;//keeping the option of decimal and whole number
}
public double multiply(double a, double b) {
	return a * b; //keeping the option of decimal and whole number
}
public double div(double a, double b) {
	return a / b; //keeping the option of decimal and whole number
}

}

@hk8084299
Copy link

Can you please look mine following one:

package java_practice;

import java.util.Scanner;

public class Caculator1 {

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

    System.out.println("Enter First number: ");
    int a= scr.nextInt();

    System.out.println("Enter Second Number: ");
    int b= scr.nextInt();
    int c= a+b;
    System.out.println(" The result of c :" + c);


    System.out.println("for Addition, enter 1, " + "for Subtraction, enter 2," + " for Multiplication, enter 3,"+ "for Division, enter 4");

    int res= scr.nextInt();

    if (res==1){

        int result= cal.add(a,b);
        System.out.println("result is " + result);
    }
    else if(res==2){
        int result= cal.sub(a,b);
        System.out.println("result is " + result);
    }

    else if(res==3){
        int result= cal.mult(a,b);
        System.out.println("result is " + result);
    }
    else if(res==4){
        int result= cal.div(a,b);
        System.out.println("result is " + result);
    }

// long c = a + b;
// System.out.println("Total number for c is :" + c);

}

}

package java_practice;

public class Calculator {
public int add(int a, int b) {
int result=a+b;
return result;
}

public int sub(int a, int b) {
    int result=a-b;
    return result;

}

public int mult(int a, int b) {
    int result= a*b;
    return result;
}

public int div(int a, int b) {
    int result=a/b;
    return result;
}

}

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