• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please solve this program and help me out clearly

 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code itself has the control flow explained. Follow the single-line comments. you will get through it.
CheerUp, Its easy
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

whats the question...??

Regards
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik, could you explain what the code outputs when you compiled it, and why you think it worked in that way?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic