Click Here To Follow our Telegram Channel for more such news and amazing free stuffs.
Telegram Channel - https://t.me/codexelltech
import java.util.Scanner;
public class Calculator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter two numbers:");
//nextDouble() reads the next double from the keyboard
double first = in.nextDouble();
double second = in.nextDouble();
System.out.println("Enter an operator (+, -, *, /): ");
char operator = in.next().charAt(0);
in.close();
double result;
switch(operator)
{
case '+':
result = first+second;
System.out.println("Sum =" +result);
break;
case '-':
result = first-second;
System.out.println("Difference =" +result);
break;
case '*':
result = first*second;
System.out.println("Product =" +result);
break;
case '/':
result = first/second;
System.out.println("Division =" +result);
break;
default:
System.out.println("Error! operator is not correct");
return;
}
}
}
Output:
Enter two numbers:
34
56
Enter an operator (+, -, *, /):
+
Sum = 90.0
Click Here To Follow our Telegram Channel for more such news and amazing free stuffs.
Telegram Channel - https://t.me/codexelltech
Click here to visit www.codexell.tech for more such references.
Telegram Channel - https://t.me/codexelltech
import java.util.Scanner;
public class Calculator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter two numbers:");
//nextDouble() reads the next double from the keyboard
double first = in.nextDouble();
double second = in.nextDouble();
System.out.println("Enter an operator (+, -, *, /): ");
char operator = in.next().charAt(0);
in.close();
double result;
switch(operator)
{
case '+':
result = first+second;
System.out.println("Sum =" +result);
break;
case '-':
result = first-second;
System.out.println("Difference =" +result);
break;
case '*':
result = first*second;
System.out.println("Product =" +result);
break;
case '/':
result = first/second;
System.out.println("Division =" +result);
break;
default:
System.out.println("Error! operator is not correct");
return;
}
}
}
Output:
Enter two numbers:
34
56
Enter an operator (+, -, *, /):
+
Sum = 90.0
Click Here To Follow our Telegram Channel for more such news and amazing free stuffs.
Telegram Channel - https://t.me/codexelltech
Click here to visit www.codexell.tech for more such references.