• Post Reply Bookmark Topic Watch Topic
  • New Topic

loops and arrays  RSS feed

 
Sabina Belyaeva
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, everyone!
I have some problems with this code.
The idea is to make a code which allows two add two numbers and display the results.
But it doen't work
Please, explain me why.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saying "it doesn't work" is not the best way to get responses from people.  Instead, post the error message.

I went ahead and run the code and I got this error:

So an index to an array is out of bounds (too large or too small).  Indexes start at zero, to an array of size 2 will have indexes 0 and 1.  Can you see what's wrong with the inner for-loop?  Can you predict what will happen with the outer for-loop?
 
Sabina Belyaeva
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Saying "it doesn't work" is not the best way to get responses from people.  Instead, post the error message.

I went ahead and run the code and I got this error:

So an index to an array is out of bounds (too large or too small).  Indexes start at zero, to an array of size 2 will have indexes 0 and 1.  Can you see what's wrong with the inner for-loop?  Can you predict what will happen with the outer for-loop?

Thank you for advice, it was my first post.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and welcome to the Ranch
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sabina Belyaeva wrote:Thank you for advice, it was my first post.

But what if someone hadn't seen that post?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!