Skip to content
Open
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
45 changes: 45 additions & 0 deletions Shreeya.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.util.Scanner;

public class Calculator {

public static void main(String[] args) {

Scanner reader = new Scanner(System.in);
System.out.print("Enter two numbers: ");

// nextDouble() reads the next double from the keyboard
double first = reader.nextDouble();
double second = reader.nextDouble();

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

double result;

switch(operator)
{
case '+':
result = first + second;
break;

case '-':
result = first - second;
break;

case '*':
result = first * second;
break;

case '/':
result = first / second;
break;

// operator doesn't match any case constant (+, -, *, /)
default:
System.out.printf("Error! operator is not correct");
return;
}

System.out.printf("%.1f %c %.1f = %.1f", first, operator, second, result);
}
}