Question

Task 6: Write a Java program to make a calculator. The calculator should add, subtract, multiply and divide the numbers inser
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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 :");

double first = reader .nextDouble();

dohble 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;

default :

System.out printf("Error ! operator is not correct ");

return;

}

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

}

}

Add a comment
Know the answer?
Add Answer to:
Task 6: Write a Java program to make a calculator. The calculator should add, subtract, multiply...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT