• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Errors - PLEASE HELP!

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm having some problems with some code I've written- I keep getting errors.I have had a look at the code myself but think that a new pair of eyes may be needed beacuse I probably have made a stupid mistake somewhere but can't seem to find it. Just to provide you with some information - this class is used by another class and it obtains an array from another class also. The errors I'm receiving are:
- Syntax error on keyword "public"; ";", "," expectedline 10
- all cannot be resolvedline 20
- Syntax error on token "row", "]" expectedline 38
PLEASE HELP. The code is:
class Clusteringclass {
distances dist = new distances();
double theRow = 1;
double theCoulmn =0;
double newRow = 1


public Clusteringclass(){
dist.getMatrix();
}
private void obtainClusters(double distanceMatrix[][]){
for (int i=0;i<distanceMatrix.length; ++i){
for (int all = 1; all<distanceMatrix.length; ++all)
for (double checkDistanceVal = 100; checkDistanceVal > distanceMatrix[i][all] && distanceMatrix[i][all] !=0
checkDistanceVal = distanceMatrix[i][all];/*This will hold the final value ie, the value with the smallest distance.*/
double row = i;
double column = 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;
}
}
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need a semi-colon on this line...

try that for starters.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naf
First it would help if you used the code tags to format your code, it makes it more readable. Also, if you're going to post a lot of code and then mention line numbers you should highlight or somehow mark those lines so we can tell what the lines in question are.
Fred is right, you need a semi colon on the line indicated.
Also, it lloks like, in this line:
for (int all = 1; all<distanceMatrix.length; ++all)
you declare a variable 'all'. that variable will be local to the block it is declared in and not visible outside of the block. In this case the for statement has no braces so the statement executed within the for loop would be the very next line. In any code after that line the variable 'all' would not be visible. So, in the line:
checkDistanceVal = distanceMatrix[i][all];/*This will hold the final value ie, the value with the smallest distance.*/
It can't see the variable. IF it needs to then declare all before the for statement so it local to the method instead of the for statement.
Hope that helps
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just a java newb, but shouldn't it be "all++" instead of "++all"?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Andrew Hocker:
I'm just a java newb, but shouldn't it be "all++" instead of "++all"?


Either will work in this context. The difference is when these operators are used within another expression: all++ evaluates to the value of all BEFORE incrementing but ++all evaluates to the value of all AFTER incrementing. To see this in action, try the following example:
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you double-posted. Here's what I added in the other post:
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic