Ask Question
2 January, 23:41

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. 3 January, 02:44
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers