Home>

public class Test {
public static void main (String [] args) {
int list [] = {1, 2, 3, 4, 5, 6};

for (int i = 1;i<list.length;i ++)
list [i] = list [i-1];

for (int i = 0;i<list.length;i ++)
System.out.print (list [i] +"");
}
}

a. 1 2 3 4 5 6
b. 1 1 1 1 1 1
c. 2 3 4 5 6 6
d. 2 3 4 5 6 1
Key: b

I don't know how to sort.
Best regard.

  • Answer # 1

    Does theexecution resultmean b when you look at the previous question?
    If so, the questioner makes a big mistake.This is not a sort program.

    Now, the next question is whether the answer is b.
    This asks the behavior of the for statement as it is, so it may be easier to visualize it.
    Visualize Python, Java, JavaScript, C, C ++, Ruby code execution

    If you open the link and wait for a while, a screen like this will appear.
    Press the "Forward" button to advance the process one step.

    How to write code

    StackOverflow has a function that makes it easy to see the code.
    Open the question edit screen and press the<code>button with the code selected.

    Also, if it is a problem posted somewhere, please specify the source of the citation.