A Java Console-based Calculator with multiple operations, error handling, and history tracking.
Perfect for learning Java basics, loops, methods, exception handling, and console input/output.
Operation | Description |
---|---|
β Addition | Adds two numbers |
β Subtraction | Subtracts second number from first |
βοΈ Multiplication | Multiplies two numbers |
β Division | Divides first number by second (handles divide by zero) |
% Modulus | Calculates remainder |
x^y Power | Calculates first number raised to second number |
β Square Root | Calculates square root (handles negative numbers) |
n! Factorial | Calculates factorial of an integer (non-negative) |
π History | Keeps a log of all previous operations |
-
Clone the Repository:
First, download the project from GitHub: git clone https://github.com/Sumermal/Java-Console-Calculator.git This will create a folder your-repo-name containing the project files.
-
Open in an IDE:
Open IntelliJ IDEA (or any Java IDE). Choose Open β Select the project folder you cloned. Make sure ConsoleCalculator.java is inside the src/ directory.
-
Compile and Run:
Run in IntelliJ : Right-click ConsoleCalculator.java β Run 'ConsoleCalculator.main()' The program will open in the console, displaying the menu.
-
Using the Calculator
The program will show a menu with operations:
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Modulus (%)
6. Power (x^y)
7. Square Root (βx)
8. Factorial (n!)
9. Show History
10. Exit
Enter the number of the operation, then input your numbers.
Results will display immediately.
Option 9 shows the history of all calculations.
Option 10 exits the calculator.
-
Notes:
Division by zero β returns NaN. Square root of negative numbers β returns NaN. Factorial only supports non-negative integers.
Java 8+
Console input/output
ArrayList for history
ConsoleCalculator/
ββ src/
β ββ ConsoleCalculator.java
ββ .gitignore
ββ README.md
Lohar Sumermal
Java Developer | Backend Enthusiast