Ask Question
11 August, 04:01

What does the following loop print? int[] a = {6, 1, 9, 5, 12, 3}; int len = a. length; int x = a[0]; for (int i = 1; i < len; i++) if (a[i] < x) x = a[i]; System. out. println (x); 1. 36

2. 12

3. 1

4. 6

+4
Answers (1)
  1. 11 August, 05:30
    0
    The answer is "Option 3".

    Explanation:

    In the given code an array a[] is already initialized then a variable "len" is defined that contains the length of the array and an integer variable x is defined that contains the value 6 that is defined in the array. In the for loop the if block is defined that check the array element value is less then variable x if this condition is true the array variable holds value in x variable and compares other values. In the code value of x variable is 1 and other options are not correct that can be defined as follows:

    In option 1, In array, element 36 is not available that's why it is not correct. In option 2 and option 4, the value of x variable is 1 and it is less than 12 and 6. that's why it not correct.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What does the following loop print? int[] a = {6, 1, 9, 5, 12, 3}; int len = a. length; int x = a[0]; for (int i = 1; i < len; i++) if ...” 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