basic-calculator-java
v1.0.0
Published
A simple CLI tool to display Java source code of a basic calculator in the terminal.
Maintainers
Readme
basic-calculator-java
A lightweight NPM package whose only purpose is to display the Java source code of a basic calculator in your terminal.
Note: This package only displays the Java source code as plain text. It does not compile, interpret, or execute the Java code, and it does not prompt for user input or perform any calculations.
What It Does
When executed, this package prints the complete, formatted Java source code for a console-based calculator (BasicCalculator.java) directly to your terminal.
Usage
1. Run without installation (recommended)
You can run this package directly using npx without installing it:
npx basic-calculator-java(If testing locally within the project folder, you can run npx . or node index.js)
2. Install globally
If you prefer to install it globally on your machine:
npm install -g basic-calculator-javaOnce installed globally, you can run it from any terminal window using:
basic-calculator-javaExample Output
Running the command will print the following output to the terminal:
import java.util.Scanner;
public class BasicCalculator {
public static void main(String[] args) {
double num1, num2;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the numbers:");
num1 = sc.nextDouble();
num2 = sc.nextDouble();
System.out.println("Enter the operator (+, -, *, /):");
char operator = sc.next().charAt(0);
double result;
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 == 0) {
System.out.println("Division by zero is not allowed.");
return;
}
result = num1 / num2;
break;
default:
System.out.println("Invalid operator.");
return;
}
System.out.println("The final result:");
System.out.println(num1 + " " + operator + " " + num2 + " = " + result);
}
}