File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enhanced for loop question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enhanced for loop question." Watch "Enhanced for loop question." New topic

Enhanced for loop question.

Daniel Martins
Ranch Hand

Joined: Oct 22, 2009
Posts: 45

class Loopy{
public static void main (String [] args){
int [] x = {7,6,5,4,3,2,1};
//insert code here
System.out.print(y + " ");

Which, inserted at line 4, compiles?

Answer: for(int y: x) {

Is this answer valid for both Java 5 and 6, or only for 6?
Vivek Singh
Ranch Hand

Joined: Oct 27, 2009
Posts: 92
Use code tags....

Yes valid for both.
Daniel Martins
Ranch Hand

Joined: Oct 22, 2009
Posts: 45
Tks for your fast reply.

I will use tags next time. Tks
Ankit Garg

Joined: Aug 03, 2008
Posts: 9462


Please UseRealWords on javranch...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Enhanced for loop question.
It's not a secret anymore!