Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<li>William Rupert Waboke (@waboke)
<li>Nanribet Yohanna Kutwal, (@Nan-yohanna), Mathematics_department, U23MTH1011</li>
<li>Owaniyi Oluwafemi Micheal, (@Chuckycipher), Cybersecurity_department, U23CYS1072</li>
<li>Ali-Musaddiq Abubakar Aliyu, (@Chuckycipher), Cybersecurity_department, U23CYS1072</li>
</ol>
<li>Ahmad Muhammad Idris, (@LuffytheGoat), Physics with Electronics, U23PE1008</li>
49 changes: 49 additions & 0 deletions Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.util.Scanner;

public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter first number: ");
double num1 = scanner.nextDouble();

System.out.println("Enter second number: ");
double num2 = scanner.nextDouble();

System.out.println("Enter an operator\n" +
"(Addition,\n" +
"subtraction,\n" +
"multiplication,\n" +
"Division): ");

char operator = scanner.next().charAt(0);

double result;

switch (operator) {
case 'addition':
result = num1 + num2;
break;
case 'subtraction':
result = num1 - num2;
break;
case 'multiplication':
result = num1 * num2;
break;
case 'division5
':
if (num2 != 0) {
result = num1 / num2; // Corrected division order
} else {
System.out.println("Error! Division by zero.");
return;
}
break;
default:
System.out.println("Invalid operator!");
return;
}

System.out.println("The result is: " + result);
}
}jj