Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Simple Calculator

A basic calculator in Java with 8 operations: arithmetic, power, modulo, square root, and factorial.

Features

Operation Method Example
Addition add(a, b) 2 + 3 = 5
Subtraction subtract(a, b) 10 - 4 = 6
Multiplication multiply(a, b) 3 * 7 = 21
Division divide(a, b) 20 / 4 = 5.0
Power power(a, b) 2 ^ 10 = 1024
Modulo modulo(a, b) 17 % 5 = 2
Square root squareRoot(a) sqrt(16) = 4.0
Factorial factorial(a) 5! = 120

Division throws IllegalArgumentException when dividing by zero.

How to run

Requires Java 8 or newer.

javac Calculator.java
java Calculator

How to use as a library

Calculator calc = new Calculator();
int sum   = calc.add(2, 3);          // 5
double q  = calc.divide(20, 4);      // 5.0
int p     = calc.power(2, 10);       // 1024
long f    = calc.factorial(5);       // 120

Requirements

  • JDK 8+

Author

Zhameer Sheraz Tampugao — github.com/zhameersheraz

License

MIT — see LICENSE.

About

Basic Java calculator with 8 operations: arithmetic, power, modulo, square root, factorial.

Topics

Resources

Stars

37 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages