File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Enhanced for loop question.

Daniel Martins
Ranch Hand

Joined: Oct 22, 2009
Posts: 45
Question:

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
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Tks

Please UseRealWords on javranch...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Enhanced for loop question.