Question: // Directions: See Below // class Lab2Compound Exercises { public static void main(String args[]}{ differentOperatorsO; question20; } // 1. Review the following method (differentOperators). You

![void main(String args[]}{ differentOperatorsO; question20; } // 1. Review the following method](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f32174c295f_84466f321749288c.jpg)
// Directions: See Below // class Lab2Compound Exercises { public static void main(String args[]}{ differentOperatorsO; question20; } // 1. Review the following method (differentOperators). You will create two new methods, name them as you see fit, // and implement the following changes: // 1a. Change differentOperators() to use ONLY simple-assignment operators and not compound. All printf statements should print the // same values. // 1b. Change differentOperators to use a post-increment operator each time there used to be a pre-increment operator, // and vice versa. Does this change the result? public static void differentOperators({ int result = 11; // result is 11 System.out.println(result); result--; // result is now 10 System.out.println(result); result /=- 2; // result is now -5 System.out.println(result); result *=- 20; // result is now 100 System.out.println(result); result %=+ 4; // result is now 0 System.out.println(result); result %=+ 4; // result is now 0 System.out.println(result); result++; // result is now 1 System.out.println(result); } // 2. In the following program, using comments in this file, explain why the value "6" is printed thrice in a row: // Also, explain why "8" became "6" from line 51 to 52. public static void question20 { int i = 6; ++i; System.out.println(i); // "7" i++; System.out.println(i--); // "8" System.out.println(--i); // "6" System.out.println(i--); // "6" System.out.println(++i); // "6" } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
