Ask Question
8 February, 00:43

What is the output of the following Java code?

int[] alpha = {2, 4, 6, 8, 10};

int j;

for (j = 4; j > = 0; j--)

System. out. print (alpha[j] + " ");

System. out. println ();

+1
Answers (2)
  1. 8 February, 01:47
    0
    10 8 6 4 2

    Explanation:

    If the mentioned code put inside in a static void main () of a public class the it will produce the aforesaid output. In the code, an array is traversed from the back. As array has elements till index 4 so, loop is started with j=4 and till j=0 and each time value of j is decremented and element corresponding to that index is printed each time on a same line. After whole array printed, a new line is printed as well.
  2. 8 February, 04:11
    0
    The Output to given java code can be given as follows:

    Output:

    10 8 6 4 2

    Explanation:

    In the given java code a one-dimensional array alpha is defined that contains some elements that are "2, 4, 6, 8, 10". In the next line, a variable j is declared and both array and variable data type is an integer. In the next step, a for loop is declare that use variable j. It starts from 4 and ends when j value is greater than equal to 0 and decrements the value of variable j and inside a loop we print the value of the array. This loop prints array value in reverse order that's why the output is "10 8 6 4 2".
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What is the output of the following Java code? int[] alpha = {2, 4, 6, 8, 10}; int j; for (j = 4; j > = 0; j--) System. out. print ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers