Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 30th, 2005, 7:31 PM   #1
trumpetelf
Newbie
 
Join Date: Apr 2005
Posts: 4
Rep Power: 0 trumpetelf is on a distinguished road
checking to see if a 2D array is inbounds

I'm currently designing a program that requires the use of a 2D array. One of the important things that this program must do before executing any specific code is to verify that the arguement passed into the program is within the bounds of the array.

I want to think that the following concept is correct and I'm stuck on putting it into Java. Someone correct me if the concept is wrong!

3 arguements are passed into method: int[][] lawn; int x; int y;

//test x
for (int i = 0; i < x.length; i++)
if x > lawn[x][i]
return false;
//test y
for (int i=0; i < y.length; i++)
if y > lawn[i][y]
return false
trumpetelf is offline   Reply With Quote
Old May 1st, 2005, 4:43 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
It looks right to me, but then, the closest I've come to Java is C#. As the syntax is very similar to both C# and C++ though, it should be fine. Why not try it and find out?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 1st, 2005, 3:45 PM   #3
trumpetelf
Newbie
 
Join Date: Apr 2005
Posts: 4
Rep Power: 0 trumpetelf is on a distinguished road
I have a working solution now -- I relize in most cases it's not good to catch and ArrayIndexOutOfBoundsException since it indicates a bug, but for the purposes of my program, that's all I needed to wory about, because no matter what, if the index was out of bounds, I wanted the program to always return a specific value. So presto, there we are. :p
trumpetelf is offline   Reply With Quote
Old May 1st, 2005, 4:16 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Heh. Congrats.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:19 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC