• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can anyone explain this code from ...Java 2 Part-1 the programmers exam - page 49

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Test{

public Static void main(String [] args){

int [] [] [] x= new int [3] [] [];
int i,j;
x[0]=new int[4][];
x[1]=new int[2][];
x[2]=new int[5][];

for (i=0;i<x.length;i++)
for(j=0;i<x[i].length;j++) {

x[i][j] = new int[i+j+1];
System.out.println("size = " +x[i][j].length);
}
}
}
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check ur code...
In inner for loop, is it i<x[i].length or j<x[i].length
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a lot of things happening here. What exactly is your question about this code?
 
uday atyam
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
opps...I am sorry...the inner loop is "j<x[i].length".

Can you tell me what the output is ...
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just compile and run it.
//i = 0; x.length = 3; x[i].length = 4
size = 1
size = 2
size = 3
size = 4
//i = 1; x.length = 3; x[i].length = 2
size = 2
size = 3
//i = 2; x.length = 3; x[i].length = 5
size = 3
size = 4
size = 5
size = 6
size = 7
[ May 16, 2006: Message edited by: wise owen ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic