diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e571935..933399c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -6,3 +6,4 @@
  • Owaniyi Oluwafemi Micheal, (@Chuckycipher), Cybersecurity_department, U23CYS1072
  • Ahmad Muhammad Idris, (@LuffytheGoat), Physics with Electronics, U23PE1008
  • +
  • Prescious Solomon, (@Precioussolomin1), Computer Science, U23CS1046
  • diff --git a/Calculator.java b/Calculator.java new file mode 100644 index 0000000..98cb4f4 --- /dev/null +++ b/Calculator.java @@ -0,0 +1,43 @@ +import java.util.Scanner; + +public class Calculator { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Enter first number: "); + double num1 = scanner.nextDouble(); + + System.out.print("Enter an operator (+, -, *, /): "); + char operator = scanner.next().charAt(0); + + System.out.print("Enter second number: "); + double num2 = scanner.nextDouble(); + + double result; + switch (operator) { + case '+': + result = num1 + num2; + break; + case '-': + result = num1 - num2; + break; + case '*': + result = num1 * num2; + break; + case '/': + if (num2 != 0) { + result = num1 / num2; + } else { + System.out.println("Error! Division by zero."); + return; + } + break; + default: + System.out.println("Invalid operator!"); + return; + } + + System.out.println("The result is: " + result); + scanner.close(); + } +}