Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InnocentDaksh63_calculator.java #421

Merged
merged 1 commit into from
Oct 2, 2021
Merged
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
54 changes: 54 additions & 0 deletions InnocentDaksh63
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.util.Scanner;

public class JavaExample {

public static void main(String[] args) {

double num1, num2;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first number:");

/* We are using data type double so that user
* can enter integer as well as floating point
* value
*/
num1 = scanner.nextDouble();
System.out.print("Enter second number:");
num2 = scanner.nextDouble();

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

scanner.close();
double output;

switch(operator)
{
case '+':
output = num1 + num2;
break;

case '-':
output = num1 - num2;
break;

case '*':
output = num1 * num2;
break;

case '/':
output = num1 / num2;
break;

/* If user enters any other operator or char apart from
* +, -, * and /, then display an error message to user
*
*/
default:
System.out.printf("You have entered wrong operator");
return;
}

System.out.println(num1+" "+operator+" "+num2+": "+output);
}
}