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 }

25th Mar 2017, 3:39 PM
bobo
2 Answers
+ 13
You missed the semicolon after this.str = str Also there is an extra semicolon inside if statement
25th Mar 2017, 3:47 PM
Shamima Yasmin
Shamima Yasmin - avatar
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 } }
25th Mar 2017, 5:19 PM
à€Šà„‡à€”à„‡à€‚à€Šà„à€° à€źà€čà€Ÿà€œà€š (Devender)
à€Šà„‡à€”à„‡à€‚à€Šà„à€° à€źà€čà€Ÿà€œà€š (Devender) - avatar