You have been asked to develop a Java program that prints the elements of an array in reverse order. Which looping statement cannot be used to meet the requirement?
Only with A it's not possible to access the elements in the array in a special order of last to first. With standard for, while and do-while you can always access the array in the order you want. with enhanced for you only receive the element itself, you don't acces the array.
To print the array in reverse order with an enhanced for loop, you would need to reverse the order of the array before you traverse it with the enhanced for loop.
A is the correct answer.
Enhanced for loop cannot be used for traverse an array in reverse order. Rest all loops can be used. Check on internet for solutions to traverse array in reverse order using Standard For, While and Do-While Loops.
Answer D is incorrect. You can use Do-while to print an array in reverse order. Example:
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};
int index = array.length - 1;
do {
System.out.println(array[index]);
index--;
} while (index >= 0);
}
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
electri
4 weeks agokrysitian
3 months, 4 weeks agotabrezshaikh13
12 months agoCintiaMoon
1 year ago