nerdexam
Oracle

1Z0-819 · Question #118

Given: public static void print(int[] nums) { // Add code here } Which of the following code fragments can be inserted within the print() method, so that all the numbers from 1 to 5 are printed to…

The correct answer is B. for (var i=0; i<nums.length; ++i){ System.out.println(nums[i]);} D. for (int i=0; j=0; i<nums.length-1; ++i){ System.out.println(nums[i]);}. See the full explanation below for the reasoning.

Question

Given: public static void print(int[] nums) { // Add code here } Which of the following code fragments can be inserted within the print() method, so that all the numbers from 1 to 5 are printed to the console?

Options

  • Afor (int i=0; i<10 && i<nums.length;){ System.out.println(nums[i]);}
  • Bfor (var i=0; i<nums.length; ++i){ System.out.println(nums[i]);}
  • Cfor (int i = nums.length; i>=0; i--){ System.out.println(nums[i]);}
  • Dfor (int i=0; j=0; i<nums.length-1; ++i){ System.out.println(nums[i]);}
  • Efor (var i=0; j=0; i<nums.length-1; ++i){ System.out.println(nums[j]);}

How the community answered

(30 responses)
  • A
    3% (1)
  • B
    83% (25)
  • C
    3% (1)
  • E
    10% (3)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice