wood burning stoves 2.0*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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: 9307
    
  17

Tks

Please UseRealWords on javranch...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
Consider Paul's rocket mass heater.
 
subject: Enhanced for loop question.