
Hans K. answered 03/27/15
Tutor
4
(4)
Benefit from Decades of Academic and Industry Experience in Computing
Luke, I gather you have all the instructions needed in the program but need to put them in the correct order for the program to do what it is supposed to do.
It may help you to keep in mind the usual flow of a small program like this:
1) the program asks the user (prints) to provide the values that it needs
2) the program reads (scans) the values provided by the user
3) the program performs the required computations
4) the program provides the user with the results of the computations (prints)
5) the program stops
Comments:
1) and 2) are usually repeated for each value needed.
If 3) does not actually require much work, 3) is sometimes combined with 4).
The last instruction of a program does not need to be an explicit stop; a program normally stops anyway when it runs out of instructions.
This program creates two scanners where one would have sufficed. Multiple scanners are needed only if the input is coming from multiple sources, like the user's keyboard and a file.
Good luck!

Hans K.
In Java, variables such as x, y, a and b must be declared before they are used. But they do not need to be declared at the beginning of the program. Common practice in Java is to declare them at the point where you first need them. That way, when you later
find that you don't actually need them you're more likely to remove the declaration when you remove the code that uses them.
Calling the System method exit() causes your program to stop. So any instructions you put after the call to exit() will never be executed. Not much point in that.
Report
03/28/15
Luke S.
03/27/15