Question: 1For the program below, explain the following: a. The style error (compiles OK, but not appreciated by humans). b. The logic error such that the
1For the program below, explain the following: a. The style error (compiles OK, but not appreciated by humans). b. The logic error such that the program doesnt do what is expected. c. The compiler error. You may enter the code to find see the compiler error, but you must explain the
actual programming mistake.
int x = 3, y = 2; if (x <= y)
System.out.println(x + " is less than or"); System.out.println("equal to " + y); else System.out.println(x + " is greater than"); System.out.println(y);
2Rewrite the program from the problem above to eliminate the errors.
3What is the output of the two separate programs below?
| (a) int x = 0; if (x < 3) { System.out.println(x); x = x + 1; } System.out.println(x); | (b) x = 0; while (x < 3) { System.out.println(x); x = x + 1; } System.out.println(x); |
4. Write a program similar to the while loop in (b) above that prints the same output in reverse order. In other words, the same numbers should be printed, but starting with the highest and ending with the lowest. NOTE: You may test your answer using Java, but you must write the main algorithm in the same document you created for the other written problems.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
