Menu
Topics Index
...
`

Arrays break and print statments


If you need explanation Read this topic

If you need Answer Take test on this topic

Arrays break and print statments
What will be the output of the following program?
public class Printstatment14 {
    public static void Elements(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            boolean isValid = false;
            for (int j = 0; j < i; j++) {
                if (arr[i] == arr[j]) {
                    isValid = true;
                    break;
                }
            }
            if (!isValid) {
                System.out.print(arr[i] + " ");
            }
        }
    }
    public static void main(String a[]) {
        int[] nums = {5, 2, 7, 2, 4, 7, 8, 2, 3};
        Printstatment14.Elements(nums);
    }
}

A. 5 2 7 4 8 3
B. 5 4 7 8 3
C. 4 7 8 2
D. 2 7
E. 2
F. Compilation Error or Runtime Error
Topic: Static and Non Static Variables - Static and Non Static Methods

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

a

Posted by Ramkumar Boggarapu    2013-06-26 03:30:15


A is answer since first 2 elements are printed as it is without going for inner if condition

Posted by Karteek Paruchuri    2013-06-26 03:30:31


a because is valid is true when arr[i]==arr[j] for 5,2,7,8,4,3  for all values

Posted by Ramkumar Boggarapu    2013-06-26 03:31:18


Congratulations Karteek Paruchuri. You are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-06-26 12:26:42


got the RC thankyou

Posted by Karteek Paruchuri    2013-06-29 06:04:34


© meritcampus 2019

All Rights Reserved.

Open In App