| Author |
Please solve this program and help me out clearly
|
Karu Raj
Ranch Hand
Joined: Aug 31, 2005
Posts: 479
|
posted

0
|
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: 973
|
|
hi, whats the question...?? Regards
|
 |
Marcus Green
arch rival
Rancher
Joined: Sep 14, 1999
Posts: 2813
|
posted

0
|
|
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
|
 |
 |
|
|
subject: Please solve this program and help me out clearly
|
|
|