Created
April 29, 2020 17:46
-
-
Save singhrahuldps/b6c067f201d36efe1849505854b3bf5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Program to perform mathematical operations on two numbers | |
| double num1,num2; | |
| String operation; | |
| Scanner scanner = new Scanner(System.in); | |
| System.out.println("Enter first number"); | |
| num1 = scanner.nextDouble(); | |
| System.out.println("Enter second number"); | |
| num2 = scanner.nextDouble(); | |
| System.out.println("Enter the operation to perform (+,-,*,/)"); | |
| operation = scanner.next(); | |
| if(operation.equals("+")) { // This code block runs if the condition is true | |
| System.out.println(num1 + num2); | |
| }else if(operation.equals("-")) { // This is only executed if above if fails | |
| System.out.println(num1 - num2); | |
| }else if(operation.equals("*")) { | |
| System.out.println(num1 * num2); | |
| }else{ // if no above conditions match, this is executed | |
| System.out.println(num1 / num2); | |
| } | |
| // Always close the scanner | |
| scanner.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment