Menu
Question Index
...

What will be the output of the following program?

public class DigitsMath {
    public static void main(String[] args) {
        int i, len = 0, a[] = {1, 2, 3, 4, 5, 42, 6, 7, 8, 9, 10};
        do {
            len = len + 1;
        } while (a[len - 1] != 42);
        for (i = 0; i < len - 1; i++) {
            System.out.print(a[i] + " ");
        }
    }
}


1 2 3 4
1 2 3 4 5
1 2 3 4 5 42
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 42 6 7 8 9 10
Some other output

Doubts

Problems

Topic: Learn Arrays And Loops

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App