What's new

Closed compareTo

Status
Not open for further replies.

Carly_Rose

Eternal Poster
Joined
Dec 8, 2018
Posts
1,288
Reaction
245
Points
348
Ano po pag kaka intindi nyo po dito mga ka phc.

Code:
if(str[i].compareTo(str[j] > 0){
   temp = str[i];
   str[i] = str[j];
   str[j] = temp;
}
 
compilation error agad, hindi match parenthesis hehe, bukod dun , medyo may idea na tayo sa laman ng "str" variable array, na hindi siya "string" (nakakalito yung name ng variable) kasi ang sabi sa line na to str[j] > 0, eh bawal yung comparison optr sa string except ==. tapos whatever the return value of compareTo must either be a true or false (kung java 'to), or integer or char (like c/c++) para maging conditional argument sa if statement.

succession of if condition, (hindi ko na ieexplain line by line kasi obvious naman hehe) mag-eexchange value si array str[i] at str[j]

example ba to sa inyo? bat parang nakakalito hehe
 
compilation error agad, hindi match parenthesis hehe, bukod dun , medyo may idea na tayo sa laman ng "str" variable array, na hindi siya "string" (nakakalito yung name ng variable) kasi ang sabi sa line na to str[j] > 0, eh bawal yung comparison optr sa string except ==. tapos whatever the return value of compareTo must either be a true or false (kung java 'to), or integer or char (like c/c++) para maging conditional argument sa if statement.

succession of if condition, (hindi ko na ieexplain line by line kasi obvious naman hehe) mag-eexchange value si array str[i] at str[j]

example ba to sa inyo? bat parang nakakalito hehe
Yup example lang po to.
 
Code:
if(str[i].compareTo(str[j]) > 0)
ganito ba yan ts?.
Kung ganyan ito yung output


nshot_20200407_154713_com.duy.compiler.javanide.md.jpg
sa output ka lang tumingin. Tapos na dyan na din yung reference sa result ng str.compareTo([j]). Alam mo naman siguro kung paano mg work si compareTo()

i analyze mo nalang sir🙂.
Sana nakatulong.
 

Attachments

Status
Not open for further replies.

Similar threads

Back
Top