Forums Register Login

Errors - can't understand why. HELP!!!

+Pie Number of slices to send: Send
I don't know why I keep getting these errors. I have looked at the coed and as far as I can see the variables that cause the errors to arise are within scope and to be honest the errors just don't seem to be making any sense.

class Clusteringclass {
distances dist = new distances();
double theRow = 1;
double theCoulmn =0;
double newRow = 1;

public Clusteringclass(){
dist.getMatrix();
}
private void obtainClusters(double distanceMatrix[][]){
int all;
//int i;
for (int i=0;i<distanceMatrix.length; ++i){
for (all = 1; all<distanceMatrix.length; ++all)
for (double checkDistanceVal = 100; checkDistanceVal > distanceMatrix[i][all] && distanceMatrix[i][all] !=0;
checkDistanceVal = distanceMatrix[i][all] )
//checkDistanceVal = distanceMatrix[i][all];/*This will hold the final value ie, the value with the smallest distance.*/
double row =(double)i;
double column = (double)all;/*These assignments ensure that the corresponding row and column numbers are stored for the
shortest value.*/

}
}

public double[][] addElement(double[][] distanceMatrix, double row, double column ){

double[][] newArray = new double [distanceMatrix.length - 1][distanceMatrix.length - 1];/*Creates a brand new array of greater
length*/
for ( int i = 0; i < distanceMatrix.length; i++){
system.out.println (i+"\n");
if (i != row && i != column){/*As long as the element of distance matrix being covered is not*/
newArray[i - 1] = distanceMatrix[i];/*Assigns elements of the distance matrix to the new Array. use -1 because obviously
the array size will decrease since the rows that are of the shortest distance will be amalgamated into 1. */
}

}
for (int i = 0; i < theDistanceMatrix.length; ++i){
newArray[newRow][theColumn] = Math.min(double [row][i], double [column][i]);/*Puts the minimum value into the new array at the
beginning.*/
++newRow;/*Only increment the row value because going to input the new values downwards. */

}
distanceMatrix = newArray;
return distanceMatrix;
}
}
[ March 05, 2004: Message edited by: Naf Rash ]
+Pie Number of slices to send: Send
What errors? I think you forgot to post them with the code...
Also, can you directly cut'n'paste your code into your code tags so the indention is in place? It's very difficult to read it otherwise. (You don't have to enter a new post altogether--you're free to edit the one you already made, just click the notepad/pencil at the top of that post and edit away.)
sev
+Pie Number of slices to send: Send
Sorry forgot to mention the errors. They are:
Syntax error on token "row", ".", "[" expectedline 21
Syntax error on token "row", "]" expectedline 43
+Pie Number of slices to send: Send
There are seveal syntax errors, and fixing one leads to the creation of others. I'll list some of the errors that need to be fixed.
1. double theCoulmn =0; // Should be double theColumn =0;

2. system.out.println(...); // Should be System.out.println(...);

3. newArray[newRow][theColumn] = Math.min(double [row][i], double [column][i]);
"double" is not the name of an array. I think you want Math.min(distanceMatrix[row][i], distanceMatrix[column][i]);

4. for (int i = 0; i < theDistanceMatrix.length; ++i){
There is no "theDistanceMatrix" ... should be "i < distanceMatrix.length".

5. Since you are using "theRow", "theColumn" and "newRow" as array indexes, they should be declared as "int", not "double".

6. Based on how you're using it, the line "for (all = 1; all<distanceMatrix.length; ++all)"
should probably be "for (all = 1; all<distanceMatrix[i].length; ++all) (do you really want to start with "all=1", or "all=0"?)

7. For some reason it doesn't like the line " double row =(double)i;" right after the "for" loop. Even if you are only doing one thing inside of a control statement (if, for, while), it's not a bad idea to enclose it in curly braces. Just uncomment out the line right before it, which is probably what you want to happen inside of the loop.

These are just syntax errors. Once you get it clean-compiled you can worry about the logic errors.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 738 times.
Similar Threads
Syntax error- HELP
Referring to an array-HELP!
Arrays -HELP!!!!!!!
For loop error?
Errors - PLEASE HELP!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:43:02.