🔒 Closed compareTo

Status
Not open for further replies.

Carly_Rose

Eternal Poster
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.webp
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.
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 315
    Views
  • 3
    Participants
Last reply from:
meta29

Online now

Members online
1,087
Guests online
854
Total visitors
1,941

Forum statistics

Threads
2,277,000
Posts
28,973,674
Members
1,229,682
Latest member
JhayPureno13
Back
Top