මේක කරන්න හොඳ විදිහක් තියෙනවාද java

Challenger SRT8

Well-known member
  • Dec 2, 2013
    9,151
    5,388
    113
    404
    String xxx = "Foo"; // this comes from an argument
    String a = xxx.equals("Foo")? "Bar" : "Foo" ;
    String b = a.equals("Foo")? "Bar" : "Foo" ;

    සරලව කිව්වොත් එන value එක අනුව a, b සෙට් වෙන්න ඕනේ

    Foo ආවොත් a=bar b=foo
    Bar ආවොත් a=Foo b=bar
    ------ Post added on Jun 21, 2022 at 1:16 PM
     

    Challenger SRT8

    Well-known member
  • Dec 2, 2013
    9,151
    5,388
    113
    404
    ඔකෙ foo, bar ඇරෙන්න වෙන ඉන්පුට් එකක් ආවත් A, B වැරදියට assign වෙනව.

    if (condition1) {
    } else if (condition2) {
    }

    selection ගොඩක් නම් switch case
    ඉන්පුට් එක දැනට foo, bar විතරයි. ඒක නිසා Method එකක් දාලා repetitive code එක අයින් කලා. ඉන්පුට් වැඩි උනොත් switch case දානවා
     
    • Like
    Reactions: Amith0424

    හෙළයෙක්

    Well-known member
  • Apr 26, 2014
    49,319
    100,170
    113
    mehema karana
    Java:
    String xxx = "Foo"; // this comes from an argument
    
    //Foo ආවොත් a=bar b=foo
    //Bar ආවොත් a=Foo b=bar
    
    String a = xxx.equals("Foo")? "bar" : "foo" ;
    String b = xxx.equals("Foo")? "foo" : "bar" ;

    dekatama xxx compare karana

    @Challenger SRT8 meke podi case ekak thiyenawa BAR kiyana eka exact check wen ne ne. hariyanama eka e nisa switch case
    ------ Post added on Jun 22, 2022 at 6:44 AM
     
    • Like
    Reactions: Challenger SRT8

    Challenger SRT8

    Well-known member
  • Dec 2, 2013
    9,151
    5,388
    113
    404
    mehema karana
    Java:
    String xxx = "Foo"; // this comes from an argument
    
    //Foo ආවොත් a=bar b=foo
    //Bar ආවොත් a=Foo b=bar
    
    String a = xxx.equals("Foo")? "bar" : "foo" ;
    String b = xxx.equals("Foo")? "foo" : "bar" ;

    dekatama xxx compare karana

    @Challenger SRT8 meke podi case ekak thiyenawa BAR kiyana eka exact check wen ne ne. hariyanama eka e nisa switch case
    ------ Post added on Jun 22, 2022 at 6:44 AM
    ඔව් චෙක් වෙන්නේ නැති එකක් තියෙනවා. ඒත් foo, bar හරියට true false වගේ. ටිකක් හිතලා බලන්න ඕන චෙක් වෙන්නෙ නැති එක.