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 Please solve this program and help me out clearly 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 "Please solve this program and help me out clearly " Watch "Please solve this program and help me out clearly " New topic
Author

Please solve this program and help me out clearly

Karu Raj
Ranch Hand

Joined: Aug 31, 2005
Posts: 479
class LabeledBreakOut
{
public static void main(String[] args)
{
int[][] squareMatrix = {{4, 3, 5}, {2, 1, 6}, {9, 7, 8}};
int sum = 0;
System.out.println(+squareMatrix.length);
outer: // label
for (int i = 0; i < squareMatrix.length; ++i)

{ // (1)
for (int j = 0; j < squareMatrix[i].length; ++j)
{ // (2)
if (j == i) break; // (3) Terminate this loop.
// Control to (5).
System.out.println("Element[" + i + ", " + j + "]: " +squareMatrix[i][j]);
sum += squareMatrix[i][j];
if (sum > 10)
break outer;// (4) Terminate both loops.
// Control to (6).
} // end inner loop
// (5) Continue with outer loop.
} // end outer loop
// (6) Continue here.
System.out.println("sum: " + sum);
}
}
Kalyana Sundaram
Ranch Hand

Joined: Mar 18, 2005
Posts: 94
The code itself has the control flow explained. Follow the single-line comments. you will get through it.
CheerUp, Its easy


Only those who will risk going too far can possibly find out how far one can go !!!
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
hi,

whats the question...??

Regards
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
Karthik, could you explain what the code outputs when you compiled it, and why you think it worked in that way?


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please solve this program and help me out clearly
 
Similar Threads
Please help me out this problem.look at last line
Help with loop label problem
switch and labeled break
Label (Continue)
labeled continue statement?