Java OCA OCP Practice Question 426

Question

What can you do to make the following code compile?

public class Main  { 
    public static void main (String [] args)  { 
        int [] values =  { 10, 20, 30  }; 
        for ( /* put code here */ ){ 
        } 
     } 
} 

Select 2 options

  • A. int k : values
  • B. int k in values
  • C. int k; k<0; k++
  • D. ;;
  • E. ; k<values.length;k++


Correct Options are  : A D

Note

Option C. is wrong since k must be initialized first.

So it should be: int k=0; k<0; k++

Option D. will cause an infinite loop, but it is valid.

Option E. is wrong. k needs to be declared first.




PreviousNext

Related