import [Link].
Scanner; public class Calculator { public static void main(String[] args) { // Create a
Scanner object for user input Scanner scanner = new Scanner([Link]); // Display welcome
message [Link]("Welcome to the Simple Calculator!"); // Prompt user to enter two
numbers [Link]("Enter first number: "); double num1 = [Link]();
[Link]("Enter second number: "); double num2 = [Link](); // Prompt user to
choose an operation [Link]("Choose an operation: +, -, *, /"); char operator =
[Link]().charAt(0); double result; // Perform the chosen operation switch (operator) { case '+':
result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2;
break; case '/': // Check if the second number is not zero to avoid division by zero if (num2 != 0)
{ result = num2 / num1; } else { [Link]("Error! Division by zero."); return; } break;
default: [Link]("Invalid operator!"); return; } // Display the result
[Link]("The result is: " + result);
import [Link];
public class Cal {
public static void main(String[] args) {
// Create a Scanner object for user input
Scanner scanner = new Scanner([Link]);
// Display welcome message
[Link]("Welcome to the Simple Calculator!");
// Prompt user to enter two numbers
[Link]("Enter first number: ");
double num1 = [Link]();
[Link]("Enter second number: ");
double num2 = [Link]();
// Prompt user to choose an operation
[Link]("Choose an operation: +, -, *, /");
char operator = [Link]().charAt(0);
double result;
// Perform the chosen operation
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
// Check if the second number is not zero to avoid division by zero
if (num2 != 0) {
result = num2 / num1;
} else {
[Link]("Error! Division by zero.");
return;
break;
default:
[Link]("Invalid operator!");
return;
// Display the result
[Link]("The result is: " + result);