BuiltWithNOF
Read 2 Dim Array

Predict the output the the following code:

import java.applet.Applet;
import java.awt.*;

public class NestForOut extends Applet
{

int board[][];
int row,col;

public void init()
{
board = new int[3][5];
board[1][0]=9;
for (int x=0; x<3; x++)
for (int y=1; y<4; y++)
{
if (x == y) board[x][y] = x+y;
if (x<y) board[x][y] = y-x;
else (board[x][y] = x-y+2);
}

}


public void paint(Graphics g)
{
for (int r=0; r<3; r++)
{
for (int c=0; c<5; c++)
{
g.drawString(String.valueOf(board[r][c]),c*20,r*20+20);
}
}
}
}

 

[Home] [Syllabus] [Sessions]