About Question com.enthuware.jfcja.v8.2.380 :

Oracle Certified Foundations Associate Java Certification Questions and Discussion
1Z0-811

Moderator: admin

Post Reply
Maria Teresa Lorenzo
Posts: 5
Joined: Fri Nov 18, 2022 2:45 pm
Contact:

About Question com.enthuware.jfcja.v8.2.380 :

Post by Maria Teresa Lorenzo »

Hi,

Can anybody explain the workings of the second continue statement below? my understanding is that i == 3, will skip the index position of 4 and move to the next number, 5. - Thank you for your help.

What can be inserted in the following code so that it will print exactly 2345 when compiled and run?

Code: Select all

public class FlowTest {

    static int[] data = {1, 2, 3, 4, 5};

    public static void main(String[] args) {
        for (int i : data) {
            if (i < 2) {
                //insert code1 here
            }
            System.out.print(i);
            if (i == 3) {
                //insert code2 here
            }
        }
    }
}
Last edited by admin on Wed Apr 12, 2023 1:36 pm, edited 1 time in total.
Reason: Please put code inside [code] [/code]

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.jfcja.v8.2.380 :

Post by admin »

No, a continue statement doesn't skip the whole iteration. It only skips the remaining part of the current iteration. So, if you put continue inside if (i == 3) block, it will skip the remaining statements of that block for this iteration. But there are no statements after that anyway, so it is inconsequential. The loop will perform the next iteration with i = 4.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests