By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,738 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,738 IT Pros & Developers. It's quick & easy.

What is the output of this program?

P: 8
int[][] makeArray( int size)
{ int[][] triArray = new int[size] [];
int val=1;
for( int i = 0; i < triArray.length; i++ )
{ triArray[i] = new int[i+1];
for( int j=0; j < triArray[i].length; j++ )
{ triArray[i][j] = val++;
}
}
return triArray;
}



What is the output of this program?I have tried out in the Edit plus but its giving an error saying (;)missing after int[][] makeArray(int size) where size=4.
Jan 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: 8
int[][] makeArray( int size)
{ int[][] triArray = new int[size] [];
int val=1;
for( int i = 0; i < triArray.length; i++ )
{ triArray[i] = new int[i+1];
for( int j=0; j < triArray[i].length; j++ )
{ triArray[i][j] = val++;
}
}
return triArray;
}



What is the output of this program?I have tried out in the Edit plus but its giving an error saying semicolon missing after int[][] makeArray(int size) where size=4.
Jan 11 '07 #2

10K+
P: 13,264
int[][] makeArray( int size)
{ int[][] triArray = new int[size] [];
int val=1;
for( int i = 0; i < triArray.length; i++ )
{ triArray[i] = new int[i+1];
for( int j=0; j < triArray[i].length; j++ )
{ triArray[i][j] = val++;
}
}
return triArray;
}



What is the output of this program?I have tried out in the Edit plus but its giving an error saying semicolon missing after int[][] makeArray(int size) where size=4.


Expand|Select|Wrap|Line Numbers
  1.  
  2. int[][] makeArray( int size) {
  3.   int[][] triArray = new int[size] [];
  4.   int val=1;
  5.   for( int i = 0; i < triArray.length; i++ ) {
  6.    triArray[i] = new int[i+1];
  7.    for( int j=0; j < triArray[i].length; j++ ) {
  8.     triArray[i][j] = val++;
  9.    }
  10.   }
  11.   return triArray;
  12.  }
  13.  
Here is the indented version of your method under code tags. You should always post your code like this. Now it compiles fine on my compiler. The method as it is does not output anything to the console if that was your question. What do you think is the output?
Jan 11 '07 #3

10K+
P: 13,264
int[][] makeArray( int size)
{ int[][] triArray = new int[size] [];
int val=1;
for( int i = 0; i < triArray.length; i++ )
{ triArray[i] = new int[i+1];
for( int j=0; j < triArray[i].length; j++ )
{ triArray[i][j] = val++;
}
}
return triArray;
}



What is the output of this program?I have tried out in the Edit plus but its giving an error saying (;)missing after int[][] makeArray(int size) where size=4.
Double posting is very bad. Now I have to merge your two threads.
Jan 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.