Java program create a simple calculater program


This programme is important for a simple calculater program
 java.util.Scanner;

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

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

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

    System.out.println("Enter the operator (+, -, *, /):");
    char operator = scanner.next().charAt(0);

    double result;

    switch(operator) {
      case '+':
        result = num1 + num2;
        break;
      case '-':
        result = num1 - num2;
        break;
      case '*':
        result = num1 * num2;
        break;
      case '/':
        result = num1 / num2;
        break;
      default:
        System.out.println("Invalid operator");
        return;
    }

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

Comments

Popular posts from this blog

Top 10 earning apps in 2023

Top 10 app for blog writing jobs

What is crypto currency

Blogger ke Web site ko surch console me kaise laye

SEO tools for bigginer

Best online earning apps

Blogger ke Web site ka SEO kaise karte hai

Top 10 crypto currency in the world

Blogger ke Web site ko rank kaise kare