Calculator

Run Settings
LanguageJava
Language Version
Run Command
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Welcome to Calculator!!"); System.out.println("'+' Addition"); System.out.println("'-' Subtraction"); System.out.println("'*' Multiplication"); System.out.println("'/' Division\n"); while(true){ System.out.println("Please choose the symbols first!! |+, -, *, /|\n"); String symbols = scanner.nextLine(); if(symbols.equalsIgnoreCase("exit")){ System.out.println("Thank you for using the Calculator!!"); break; } switch (symbols){ case "+": System.out.println("First Number: "); double first_number = scanner.nextDouble(); scanner.nextLine(); System.out.println("Second Number: "); double second_number = scanner.nextDouble(); scanner.nextLine(); double result; result = first_number + second_number; System.out.println(first_number + " + " + second_number + " = " + result); break; case "-": System.out.println("First Number: "); double first_number_2 = scanner.nextDouble(); scanner.nextLine(); System.out.println("Second Number: "); double second_number_2 = scanner.nextDouble(); scanner.nextLine(); double result_2; result_2 = first_number_2 - second_number_2; System.out.println(first_number_2 + " - " + second_number_2 + " = " + result_2); break; case "*": System.out.println("First Number: "); double first_number_3 = scanner.nextDouble(); scanner.nextLine(); System.out.println("Second Number: "); double second_number_3 = scanner.nextDouble(); scanner.nextLine(); double result_3; result_3 = first_number_3 * second_number_3; System.out.println(first_number_3 + " × " + second_number_3 + " = " + result_3); break; case "/": System.out.println("First Number: "); double first_number_4 = scanner.nextDouble(); scanner.nextLine(); System.out.println("Second Number: "); double second_number_4 = scanner.nextDouble(); scanner.nextLine(); double result_4; result_4 = first_number_4 / second_number_4; System.out.println(first_number_4 + " ÷ " + second_number_4 + " = " + result_4); break; default: System.out.println("SYSMBOL INVALID!!"); break; } } scanner.close(); } }
Editor Settings
Theme
Key bindings
Full width
Lines