Error in my Java function?

Hi.

Here is my Java function:

public String ecrire(){
String temp="";
for(int i=0;i<grille.length;i++){
for(int e=0;e<grille[i].length;e++){
Temp+=Integer.toString(grille[i][e]);
}
}
temp+=" // "+Integer.toString(lacomplexite);
return Temp;
}

It's not working, but I don't know what the problem is... And what should my result be in the end?

Thanks!

deonejuan2011-07-06T05:38:04Z

Favorite Answer

1. You have 'Temp' and you have 'temp'. Java is case-sensitive
2. if grille has been declared but nothing put in it, you won't get anything

int[][] grille = {
{1,2,3,4,5,6,7},
{11,12,13,14,15,16,17},
{21,22,23,24,25,26,27}
};

public String ecrire() {
String temp ="";
for( int i = 0; i< grille.length; i++) {
for( int j = 0; j < grille[ i ].length; j++ ) {
temp += grille[ i ][ j ] + ",";
}
return temp;
}
System.out.println( ecire() );
// try that, and note I call the method() with ecire()

Kevin Lain2011-07-06T12:40:08Z

How do you know it's not working if you don't know what the result should be? ^_^;

I don't have Eclipse, or Java for that matter installed on this computer so I can;t compile this or anything but just looking at it,


Temp does not seem to be delcared, is it a global variable?
Remember that capital letters are important in Java, A is not equal to a, Temp is not the same as temp.

And what is grille. I don;t understand what data type this could possibly be ^_^; is it a one dimension or 2 dimension integer array?

Vaibhav2011-07-06T13:10:33Z

java is case-sensitive so Temp and temp are different
also to convert int to string use
String.valueOf(grille[i][e]);
same way at end