Array Initialization !!!

Hi,

Which of these statements are legal. Select the three correct answers.

A. int arr[][] = new int[5][5];

B. int[]arr[] = new int[5][5];

C. int[] arr = new int[5][];

Correct Answer: A,B,C

C is right answer? How ? When I compiling the code compiler err

coming for incompatible type(C answer) !!

pls anyone can explain the reason.

[390 byte] By [jaban_10a] at [2007-10-3 3:15:42]
# 1
C is incorrect. Either there was a typo and they mentint[][] arr = new int[5][];or the answer is plain wrong.
JoachimSauera at 2007-7-14 21:07:03 > top of Java-index,Java Essentials,New To Java...
# 2

A is the correct answer.

C cannot be the right answer because you're initializing a monodimensional array with a bidimensional one. A is right even if I like more using:

int [][]arr = new int[5][5]

Edit: sorry JoachimSauer didn't noticed you posted while I was writing my reply.

Message was edited by:

JoYsTiCk

JoYsTiCka at 2007-7-14 21:07:03 > top of Java-index,Java Essentials,New To Java...
# 3
http://www.simulationexams.com/SampleQuestions/java-certification/scjp/scjp_q1.htm...saying C is right answer ?
jaban_10a at 2007-7-14 21:07:03 > top of Java-index,Java Essentials,New To Java...
# 4

Here's more to my codeing i got done today if ne one still knows what im talking about if ne one can help

public class NFL2 {

public static String [] [] AFC = {

{"Buffalo","Miami","New England","New York Jets"},

{"Cincinnati","Baltimore","Pittsburgh","Cleveland"},

{"Jacksonville","Houston","Tennesse","Indianapolis"},

{"Oakland","San Diego","Denver","Kansas City"}

};//string at class level

public static String [] [] NFC = {

{"New York Giants","Dallas","Philadelphia","Washington"},

{"Detroit","Green Bay","Chicago","Minnesota"},

{"Atlanta","New Orleans","Tampa Bay","Carolina"},

{"St. Louis","Arizona","San Francisco","Seattle"}

};//string at class level

public static int AFCwins[][] = new int [4][4];

public static int AFCloss[][] = new int [4][4];

public static int NFCwins[][] = new int [4][4];

public static int NFCloss[][] = new int [4][4];

public static void playGame (String team1,int i, int c, String team2, int i2, int c2, String conf){

int score1 = 2 + (int)(Math.random() * 60);

int score2 = 2 + (int)(Math.random() * 60);

System.out.println(team1 + "\t"+ score1);

System.out.println("VS");

System.out.println(team2 + "\t" + score2);

if (conf.equals("A") && score1 > score2){

System.out.println(team1 + " Wins");

AFCwins[i][c]=1;

AFCloss[i][++c]=1;

}else if (conf.equals("A") && score2 > score1){

System.out.println(team2 + " Wins");

AFCwins[i][++c]=1;

AFCloss[i][c]=1;

}else if (conf.equals("N") && score1 > score2){

System.out.println(team1 + " Wins");

NFCwins[i][c]=1;

NFCloss[i][++c]=1;

}else if (conf.equals("N") && score2 > score1){

System.out.println(team1 + " Wins");

NFCwins[i][++c]=1;

NFCloss[i][c]=1;

}else{

System.out.println("This should not come up ever!");

}

System.out.println();

}//end play game

public static void main(String[] args) {

for (int i = 0; i < AFC.length; i++) {

for (int c = 0; c < AFC[i].length; c++) {

String conf="A";

playGame (AFC[i][c],i,c,AFC[i][++c],i,c, conf);

}

System.out.println();

}

for (int i2 = 0; i2 < NFC.length; i2++) {

for (int c2 = 0; c2 < NFC[i2].length; c2++) {

String conf= "N";

playGame (NFC[i2][c2],i2,c2,NFC[i2][++c2],i2,c2, conf);

}

System.out.println();

}

}//end main method

}//end class

dayv2005a at 2007-7-14 21:07:03 > top of Java-index,Java Essentials,New To Java...
# 5
wrong thread my bad guys
dayv2005a at 2007-7-14 21:07:03 > top of Java-index,Java Essentials,New To Java...
# 6
> http://www.simulationexams.com/SampleQuestions/java-ce> rtification/scjp/scjp_q1.htm> > ...saying C is right answer ?note that they do not have an explanation for this =PI'd be worried if they do!
lfschucka at 2007-7-14 21:07:03 > top of Java-index,Java Essentials,New To Java...