0
Everytime I tried to compile,it keeps giving me error but I can't seem to find the problem*.....anotherMyString [i]; return 0;*
public class MyString{ private String str; private int length; private char []chars; public MyString str(String str){ this.str = str } public char charAt(int index){ if (index < 0; || index >= chars . length) return ' ' ; else return chars [index]; } public int compareTo (MyString anotherMyString){ if (this. length != anotherMyString.length) return this.length - anotherMyString.length; for (int i = 0; i < length; i++) if (this. str[i] - anotherMyString.thestr[i] return this.str [i] - anotherMyString }
2 Respuestas
+ 13
You missed the semicolon after this.str = str
Also there is an extra semicolon inside if statement
0
public class MyString{
private String str;
private int length;
private char []chars;
public MyString str(String str){
this.str = str; // missed semi colon
}
public char charAt(int index){
// there was a ; after index < 0
if (index < 0 || index >= chars . length)
return ' ' ;
else
return chars [index];
}
public int compareTo (MyString anotherMyString){
if (this. length != anotherMyString.length)
return this.length - anotherMyString.length;
for (int i = 0; i < length; i++){
if (this. str[i] - anotherMyString.thestr[i]
return this.str [i] - anotherMyString
}
}