hello,please I have a project to do in java concerning arrays. If
somebody knows the answer,please send it to my email adress
(ziyade4@hotmail.com),i'll be thankfull.
this is the exercice.
// Topographical maps are easily represented with two-dimensional
arrays of integer or real valued
heights. However, the bird's eye view they provide is sometimes
difficult to appreciate after a day of
lugging a 70-pound backpack.
Consider a two-dimensional array variable storing real numbers and
representing heights of a
topographical map.
Write a program that locates peaks. We define a peak as any point that
is higher than its eight
neighbors.
Write a program that locates valleys. A valley is any series of three
points along a row or column that
are lower than their twelve neighbors. (Can you deal with longer
valleys as well?)
1. Define a two-dimensional array type for holding real numbers and
having a size of maxrow times
maxcol;
2. Declare a Boolean method that tests if a point of this map
represents a peak;
3. From the main program locate all peaks and output their positions
and heights;
IF --> A valley is any series of N points along a row or column that are LOWER than their twelve neighbors. Not equal ??
then --> all points in valley must don't have diagonal neighbor lower than their values.
In valley you must find a point that is "opposite peak". All neigbors are higher. You can find this point with oziris's code. When you have this point you can search around.
sorry for my english, i have many problem to explain correctly.
Ronie wrote:
ok no problem
No solution, just idea to solve :
IF --> A valley is any series of N points along a row or column that
are LOWER than their twelve neighbors. Not equal ??
then --> all points in valley must don't have diagonal neighbor lower than
their values.
In valley you must find a point that is "opposite peak". All neigbors are
higher. You can find this point with oziris's code. When you have this
point you can search around.
sorry for my english, i have many problem to explain correctly.
IF --> A valley is any series of N points along a row or column that are LOWER than their twelve neighbors. Not equal ??
then --> all points in valley must don't have diagonal neighbor lower than their values.
In valley you must find a point that is "opposite peak". All neigbors are higher. You can find this point with oziris's code. When you have this point you can search around.
sorry for my english, i have many problem to explain correctly.
oziris
Right Cyril.
Ronie, you may also need a max(int[]) fonction that returns the max of an integer serie. Something like...
public int max(int[] integers) { if (integers.length > 1) { int[] integersWithoutFirst = new int[integers.length - 1]; System.arraycopy(integers, 1, integersWithoutFirst, 0, integers.length - 1); return Math.max(integers[0], max(integersWithoutFirst)); } else { return integers[0]; } }
-o--
Right Cyril.
Ronie, you may also need a max(int[]) fonction that returns the max of
an integer serie.
Something like...
public int max(int[] integers)
{
if (integers.length > 1)
{
int[] integersWithoutFirst = new int[integers.length - 1];
System.arraycopy(integers, 1, integersWithoutFirst, 0,
integers.length - 1);
return Math.max(integers[0], max(integersWithoutFirst));
}
else
{
return integers[0];
}
}