![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 4
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 4
Rep Power: 0
![]() |
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
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|