This activity gives you the opportunity to practise working with arithmetic operators and using brackets to clarify their order of evaluation.
In addition to the discussion of the solution in the Solution document, the project for this activity contains two classes:
Five integers have already been declared for you in the locations named A, B, C, D and E and assigned values that are to be used unchanged in the activity.
Your task is to use these five values and each of the four operators +, -, * and /, to build up an expression. The value of the expression should be as large as possible. Each value and operator is to be used once and once only. Brackets should be used to ensure the order of evaluation is the one you intend.
Run the project: you should find the result is 1 initially.
Open the class Ex2_1 and read the method calculate.
Edit the line
result = ((A + B) - (C * D)) / E;
Try to change the order in which the variables and operators appear so that the expression will have the largest possible value. You can test the effect of each modification you make by running the project again.
Your target is to get more than 3000. Good luck!
Please don't spend too long on this activity. It's only meant to let you practice with Java arithmetical operations - we aren't trying to test your mathematical skills!