Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Arrays -HELP!!!!!!!

Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way of returning an array?
I have created an array that holds a series of numbers. However, i need to use this in another method which basically gets the matrix and returns it so that it can be retrieved by another class. Can this be done? I know that to an array can be passed to another method but my issue is with resepct to actually returning it so that it can be manipulated later on.
I am enclosing some code so that you may understand where my problems lay. The errors that I have so far are:
The method getMatrix() in the type distances is not applicable for the arguments (double[][])
Syntax error on keyword "double"; "interface", "class" expected - this is with respect to the actual method getMatrix.

public double[][] manhattan() {
theSum =new int[theCount];
sum = new int [theRowCount][theCount];
/* Comparing each record attribute with the next record. The sum stores the value of the
* differences between records (based on single attributes). The first for stmt looks at
* one row at a time- the second for stmt the compares this row to all the other rows.
* For every row comparison all the attributes are considered. NOTE: the second for stmt
* starts at 2 so that the second row is considered (the first row is dealt with in the
* first for stmt).*/
for (int i=1; i<theRowCount; ++i){
for (int all = 2; all<theRowCount; ++all){
for (int k=1; k<theCount; ++k)//attributes
/* Carry out the calculations to work out the manhattan distance. If the attribute value being
* considered of type int then an exception occurrs and is caught in the catch clause- if the 2
* values differ then the distace is equal to 1 else it is equal to 0.*/
for (int c=1; c<theCount; ++c){
theSum[c]=(sum[k] - sum[all][k]);
/*Add all the attribute differences together and then square them. Stores the resulting values
* in an array. */
for (int ts=0; ts<theSum.length-1; ++ts){
distance = distance + theSum [ts];
//check to see if the result of the calculation is negative. If so, make it positive.
if (distance<0){
distance = distance*distance;
catch (NumberFormatException nfe){
if (sum[k] == sum[all][k]){
distance = 0;
else if (sum[k] == sum[all][k]){
distance =1;
}//end catch

/*Devise the matrix. For the tuples being considered ther manhattan distance is entered in the
* corresponding element of the array.This produces a matrix with the same number of column as rows.
* The size of the matrix changes since it stores some calculations that
* have been carried out on database rows. As a result the number of rows
* that the database has is called for and this determines the size of the
* matrix.*/
int row1= theRowCount, row2= theCount;
double [][] distanceMatrix;
distanceMatrix= new double [row1][row2];
for (i=1;i<row1; ++i){
for (all = 1; all<row2; ++row2)
distanceMatrix[all] =distance;
getMatrix(distanceMatrix);/*The distance matrix is passed call-by-refernce*/
//return distanceMatrix;//[all];

public double getMatrix(theDistanceMatrix[][]) {
return theDistanceMatrix[j];
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One potential problem I can see here...

there seems to be some difference between what you are supposed to be returning from this method, and what is actually being returned. I think all of the following modified versions should work, but you will have to chose which is the one you actually need!
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a version that should compile. (I don't have one of the classes you are using.) But you will get some errors about loss of precision.
There were many errors in this. I suggest you use an IDE for syntax checking such as Eclipse. You were missing matching parens, brackets, semicolons, you mis capilized and misspelled some of your variable names.
public class Clusteringclass {
distances dist = new distances();
double theRow = 1;
double theCoulmn =0;
double newRow = 1;

public Clusteringclass(){
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
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 < distanceMatrix.length; ++i){
newArray[row][column] = Math.min(distanceMatrix [row][i], distanceMatrix [column][i]);
/*Puts the minimum value into the new array at the beginning.*/
/*Only increment the row value because going to input the new values downwards. */
distanceMatrix = newArray;
return distanceMatrix;
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ March 04, 2004: Message edited by: Andrew Hocker ]
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
    Bookmark Topic Watch Topic
  • New Topic