BIT 2d semiya..

inranasingha

Well-known member
  • Jan 27, 2008
    5,818
    1,785
    113
    රජයේ රෝහල
    මේ ත්‍රෙඩය පටන් ගත්තේ BIT 2nd
    සෙමිය කරන නංගිලා මල්ලිලා අක්කලා
    අයියලා බාප්පලා පුංචි අම්මලාගේ ගැටළු වලට උත්තර හොයාගන්න...
    images

    :):):):):)
    එන්න අපි දැනුම බෙදා ගනිමු...
    සබ්ජ්ක්ට් හතරෙම තියන ගැටළු මෙතනට පෝස්ට් කරන්න.....
    මේ සතියෙ විතරක් මේ ත්‍රෙඩය උඩින්ම තියාගන්න බම්ප් එකක්වත් දාන්න..
    :cool::cool::cool::cool::cool::cool:
     

    inranasingha

    Well-known member
  • Jan 27, 2008
    5,818
    1,785
    113
    රජයේ රෝහල
    Help plzzz
    class Str{
    public static void main(String args[]){
    double value1 = 10000;
    float value2 = 35.0f;
    String str = String.valueOf(value1);
    System.out.println(str + value2);
    }
    }


    What would be the output of the program?

    Choose at least one answer.
    a. error
    b. 10000
    c. 35.0
    d. 10035.0
    e. 10000.035.0 Correct
     

    inranasingha

    Well-known member
  • Jan 27, 2008
    5,818
    1,785
    113
    රජයේ රෝහල

    Marks: 1/1
    Consider the following program written in Java.

    class Abc{
    public static void main(String args[]){
    String str1 = "Anuradhapura";
    String str2 = "Anuradhapura";
    System.out.print(str1.equals(str2));
    }
    }

    What would be the output of the program?
    Choose at least one answer.
    a. error
    b. false
    c. true
    d. Anuradhapura
    e. Anu
     

    Lalakajee

    Well-known member
  • Jun 20, 2007
    3,061
    296
    83
    In my own heart
    Help plzzz
    class Str{
    public static void main(String args[]){
    double value1 = 10000;
    float value2 = 35.0f;
    String str = String.valueOf(value1);
    System.out.println(str + value2);
    }
    }


    What would be the output of the program?

    Choose at least one answer.
    a. error
    b. 10000
    c. 35.0
    d. 10035.0
    e. 10000.035.0 Correct

    String str = String.valueOf(value1);
    converts the value 10000 to a string, which is a double(so 10000 becomes 10000.0) in this case it is "10000.0" and stores it in the variable str.
    In the System.out.println statement an addition is performed. with a string and a float.
    So it simply adds these two like this
    "10000.0"+35.0f
    and returns
    10000.035.0

    :D:D
     

    Lalakajee

    Well-known member
  • Jun 20, 2007
    3,061
    296
    83
    In my own heart

    Marks: 1/1
    Consider the following program written in Java.

    class Abc{
    public static void main(String args[]){
    String str1 = "Anuradhapura";
    String str2 = "Anuradhapura";
    System.out.print(str1.equals(str2));
    }
    }

    What would be the output of the program?
    Choose at least one answer.
    a. error
    b. false
    c. true
    d. Anuradhapura
    e. Anu

    String equals method returns true or false based on the two string which it compares, in this case, "Anuradhapura" & "Anuradhapura" which is same.
    So the answer is true.
    But if they use == the return value is false since the == checks whether it references to the same object (memory space) which is wrong.
    When a String variable is declared it always create a new object(which is a String object).
    String objects cannot be changed, they are immutable.:D:D:nerd:
     

    inranasingha

    Well-known member
  • Jan 27, 2008
    5,818
    1,785
    113
    රජයේ රෝහල
    String equals method returns true or false based on the two string which it compares, in this case, "Anuradhapura" & "Anuradhapura" which is same.
    So the answer is true.
    But if they use == the return value is false since the == checks whether it references to the same object (memory space) which is wrong.
    When a String variable is declared it always create a new object(which is a String object).
    String objects cannot be changed, they are immutable.:D:D:nerd:

    thuthi machan:):):):):)
     

    Leo_D

    Well-known member
  • Jan 26, 2011
    2,711
    560
    113
    public class test{
    public static void main(String args[]){
    boolean a=false;

    System.out.println(a=a);
    }
    }

    ai mekedi output eka false wenne?
     

    inranasingha

    Well-known member
  • Jan 27, 2008
    5,818
    1,785
    113
    රජයේ රෝහල
    public class test{
    public static void main(String args[]){
    boolean a=false;

    System.out.println(a=a);
    }
    }

    ai mekedi output eka false wenne?

    = kiyanne assgnment oprator eka.
    a=a;
    left side eke thiyana eka variable eka...
    right eke thiyana eke value eka a ta assgn karagannawa..
    mulin declare karala thiyanawa..
    eka false kiyala..
    data type eka boolean
    out put false..
    == thibbanam equalda kiyala balala ehemanam true retun karanawa nethnam false..
    a==a
    oya daala balanna..
    if any correction plz..
     
    • Like
    Reactions: Leo_D