Ads

using IJVM..can anybody help me in this question

User should be prompted to enter two non-negative numbers (say, a and b where a >0 and b > 0) line by line and then press the enter key. Your program should calculate and display the following for these numbers (see sample output below): Sum (a + b) Difference (a - b or b - a, whichever gives a positive value) Product (a x b) Power (ab)

OUTPUT Num1: 2 Num2: 10 Sum = 12 Difference = 8 Product = 20 Power = 1024 Num1: a Invalid Number Num1: x End of program

Implement the above in a loop so that the user is prompted to keep entering two numbers and the program produces the required results for each set of numbers until user enters Ã¢â?¬Å?xÃ¢â?¬Â? (character x) which should halt (end) the program.

Ã?Â· Validate your inputs to only accept non-negative numbers as input (i.e. n Ã¢â?°Â¥ 0). Hence, if user enters characters like negative numbers, alphabets or any other character; your program should display some appropriate error message and prompt for another valid number.

Ã?Â· Use appropriate subroutines (functions/methods) in your program. For example, each mathematical operation/function could be in a subroutine.

Ã?Â· Write appropriate comments and use good programming techniques in your code where possible.

Ads

View Answers

Ads

Related Tutorials/Questions & Answers: