This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 9291
    
  17

Tks

Please UseRealWords on javranch...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enhanced for loop question.
 
Similar Threads
while and post increment
what will be the output
Dont�t understand the result
Another IBM mock Exam Question
Chapter 5 K&B -Doubt