473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

still learning

here is a snipped:

Expand|Select|Wrap|Line Numbers
  1. int[][] c = new int [9][2];
  2.  
  3. ...
  4.  
  5. c[4][2] = -1;
  6.  
  7.  
  8.  
  9.  
Why does that not work?
Nov 1 '08 #1
5 1255
sukatoa
539 512MB
will you post the experimental code that makes you convinced it is not working?
Nov 1 '08 #2
sorry all my arrays give me an out of bounds error

so if i have a array_example[2][9]
and i assign array_example[2][9] = 15

it gives me an out of bouds error

if i change the declaraation to array_example[3][10]

then it works!!

why?
There really is no program because no matter what program i use arrays in, I get this type of error. (btw I know pascal, vb (all basics) delphi, javascript and a few others so its easy for me to get the methods mixed up)

help
Nov 1 '08 #3
JosAH
11,448 Expert 8TB
why?
help
If you declare an array to have 'n' elements the valid index values are:

0, 1, 2, 3 ... n-3, n-2, n-1 (count them all for reasonable values of 'n').

That's why; Java always starts its indexing at element number zero,

kind regards,

Jos
Nov 1 '08 #4
If you declare an array to have 'n' elements the valid index values are:

0, 1, 2, 3 ... n-3, n-2, n-1 (count them all for reasonable values of 'n').

That's why; Java always starts its indexing at element number zero,

kind regards,

Jos
correct - as a mater of fact the majority of programing languages start with zero on arrays

what throws me off is for example:
pascal theArray[1..10,1..5] wil give me a 10 x 5 array
basic theArray(10,5) same - 10 x 5 array

is what your saying is that the following:
theArray[10][5]
will NOT give me a 10x5 array (excluding the fact that it really is since your starting at zero) to the extent that I cannot reach the max theArray[10][5]= n ?

bear in mind that the above two examples (pascal and basic) you can STILL use [0,0] (pascal) and (0,0)(basic) to use as data.

in conclusion - so I understand java arrays - in order to achieve a 10 x 5 array (in this example) and reach those numbers (i.e. theArray[10][5] = n) it actually needs to read theArray[11][6]?

(or I suppose I could n-- for the count.

as an after thought, kinda defeats the purpose of making a chessboard[8][8] and only have access to 0 - 7 even though your looking at the number "8" in the dimension. lol
Nov 2 '08 #5
JosAH
11,448 Expert 8TB
as an after thought, kinda defeats the purpose of making a chessboard[8][8] and only have access to 0 - 7 even though your looking at the number "8" in the dimension. lol
You can't count; a board[8][8] gives you an 8x8 board indexed by the values
0,1,2,3,4,5,6 and 7 (those are eight index values).

kind regards,

Jos
Nov 2 '08 #6

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

Similar topics

25
by: Lewis Lang | last post by:
MCSD certification - is it still necessary to land a job? ... or, is it just a money-maker? Is it worth spending the money on the books and the exam? Thanks, Lewis Lang
6
by: KathyK | last post by:
Hi and Thanks in advance! I am able to link to a MSAccess 2000 db that I secured. I have removed all permissions from the Admin user and actually the whole users group and admins group. I...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
4
by: Francis | last post by:
I have followed Jon, Morten and Mohanmoss advice, but still not work. Can someone pls give some comments about the following codes of interface and implements ? 2 files, ITrans.cs and DDDBIQ.cs...
7
by: Tony Johansson | last post by:
Hello! If you want to create an GUI application using a tool in visual studion 6.0 you are forced to use MFC. I just want to know about the developing GUI application in C++ visual studio...
1
by: D. Shane Fowlkes | last post by:
I'm a fairly skilled traditional ASP/VB programmer and am learning .NET. I was (recently) surprised to read in a book about declaring and defining all my page Functions in <script...
4
by: John Salerno | last post by:
Hi everyone. I have Learning Python 2nd edition (O'Reilly) and I noticed that Wrox has a newer book out (Beginning Python) that covers version 2.4. Do you think that Learning Python is still a good...
7
by: Max | last post by:
On monday I start a semester course in Python (the alternative was Java). I was looking through the course outline and noticed the following: 1) UserDict is used. This is deprecated, right? 2)...
15
by: David Pratt | last post by:
I recently replied to MC felons post on returning strings and was in error on what I was trying to do. After running completely thru my code, I did find that I was misunderstanding how C++ works...
16
by: John Salerno | last post by:
Just something that crosses my mind every time I delve into "Learning Python" each night. Does anyone see any value in learning Python when you don't need to for school, work, or any other reason?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.