• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array  RSS feed

 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tried running this but I get an out of bound exception. Its at line 14.  Can some look over the code to see what is wrong?



 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Dagenhart wrote:
I tried running this but I get an out of bound exception.


The out of bounds exception also gives information on the index that you are trying to access. This should help greatly in helping you figure out what is wrong.

Henry
 
Paul Clements
Ranch Hand
Posts: 99
1
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol, this was a subtle one :-) Look at line 8.

ps. you should indent your code properly to make it more readable.
 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was one of my questions on my final last week. 

we had to figure out the value for c1[2] .  c2[1][1], c2[2][4], c2[3][4]. c2[3][2]

I am already have issues with trying to understand arrays like this one.  I need to find a really good video or person who can give me immediate feedback on my questions.. or a video that explains arrays in better detail than the ones I have watched on you tube.

I cant figure out why its out of bounds because I dont know how its setting up the array to begin with.
 
Liutauras Vilda
Sheriff
Posts: 4918
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not a fan of such questions, not sure what concepts they teach. These usually come up on certification exams. Who gave it to you?

Anyway, apart from the fact that author of this question is trying to confuse and get you lost among those variable names "a, b, bb, c, d..; a=0;" and later adding ';' at the end of for loop just to make this loop nonsensical, it is very easy to get confused without writing down on a paper each of their values at every step/iteration.

Also you need to understand here array of arrays. Do you know what these are and how to visualise them in your head?

Apart from that here is nothing difficult, as mentioned, just need to write down values line by line, iteration by iteration.
 
Daniel Dagenhart
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:I'm not a fan of such questions, not sure what concepts they teach. These usually come up on certification exams. Who gave it to you?

Anyway, apart from the fact that author of this question is trying to confuse and get you lost among those variable names "a, b, bb, c, d..; a=0;" and later adding ';' at the end of for loop just to make this loop nonsensical, it is very easy to get confused without writing down on a paper each of their values at every step/iteration.

Also you need to understand here array of arrays. Do you know what these are and how to visualise them in your head?

Apart from that here is nothing difficult, as mentioned, just need to write down values line by line, iteration by iteration.


This was a final exam question.  Yes he does like to try to confuse us students. Normally we would go over the tests the following week, but since it was a final, I wont see him at all. So I will not get to ever understand this problem and it being explained what is going on through it.
 
Liutauras Vilda
Sheriff
Posts: 4918
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright. So yeah, not sure what actually to explain here.

1. One thing which might could be a bit more tricky than others is to understand "array of arrays" and how to decipher that.

For instance:
So you can try to think about that in your head like (1st number within the square above represents rows indices below, 2nd number columns):


2. Second might be a tricky part is how variables get initialised.
So, in the line above only bb and c gets initialised, other variables just declared, meaning that they have no value yet, while bb holds 4 and c 0 right from the beginning.


3. Third tricky point is line 8, which basically what does, asks your attention. Moreover, it initialises variable a and reassign it multiple times - 5 times in total, which ends up in value 4 at the end (a = 0, 1, 2, 3, 4 stops).

And that is basically it - the rest is just labour job by writing down each value per line - per iteration.

Hope that helped a bit.
 
Liutauras Vilda
Sheriff
Posts: 4918
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Such questions I believe are constructed in IDE's by putting some legitimate code and letting cat to run over the keyboard for few minutes, then compile it, run it and write it down, and finally produce such question to the poor student expecting it is worth take from student some marks off because he overlooked 1 little bit but the rest got good and concept in general understood, but just was unsuccessful this particular day. "Let's see if other got it wrong too.."
 
Liutauras Vilda
Sheriff
Posts: 4918
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In contrary to myself, it might distinct students who can concentrate a bit more when it is needed from the ones who can't, but is it worth? I don't know, probably more experienced guys here could tell if there are nothing else more useful to be taught.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the goal. If the goal is to see if the student understands loop constructs and array indexing, then this is a horribly formulated question.

If the goal is to see if someone has the skills to trace through horrifically unreadable code and find a bug, then this can be a pretty good test.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!