Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
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!
3 Answers
- deonejuanLv 710 years agoFavorite 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 LainLv 610 years ago
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?
- VaibhavLv 610 years ago
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