Skip to content

Instantly share code, notes, and snippets.

@sunnyeyez123
Created November 9, 2017 06:32
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 sunnyeyez123/228bc3cb070ebd28ea0b40fdffd88e98 to your computer and use it in GitHub Desktop.
Save sunnyeyez123/228bc3cb070ebd28ea0b40fdffd88e98 to your computer and use it in GitHub Desktop.
/* a simple arithmetic calculator. */
class Calculator{
public Calculator(){
}
public int add(int a, int b){
return a+b;
}
public int subtract(int a, int b){
return a-b;
}
public int multiply(int a, int b){
return a*b;
}
public int divide(int a, int b){
if(b == 0){
System.out.println("Error! Dividing by zero is not allowed.");
return 0;
}else{
return a/b;
}
}
public int modulo(int a, int b){
if(b == 0){
System.out.println("Error! Dividing by zero is not allowed.");
return 0;
}else{
return a%b;
}
}
public static void main(String[] args){
Calculator myCalculator = new Calculator();
System.out.println(myCalculator.add(5, 7));
System.out.println(myCalculator.subtract(45, 11));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment