>

Sunday, December 16, 2012

SCJP Questions with Answers Part -1

1. String compare using == operator


public void stringConvert(){
    if("java".toUpperCase()=="java".toUpperCase())
    {
        System.out.println(true);
    }
    else
        System.out.println(false);
}


2. String compare using equals :

public void stringEquals(){
    if("java".toLowerCase().equals("JAVA".toLowerCase()))
    {
        System.out.println("true");
    }
    else
        System.out.println(false);
           
}

3.


public void stringSubstring(){
    String str="java programming";
    str.substring(0,4);
    str.replace('a', 'j');
    String stra="welcome to "+str;
    System.out.println(stra);
   
}

4.
public void zero(){
        if(-00.0==+0.000)
        {
            System.out.println(true);
        }
        else
            System.out.println(false);



ANSWERS:

1.false -> == operator check objects not contents...
2.true  -> equals modifier checks only content...
3.welcome to java programming-> value of string replaced but not stored in anywhere.... So sting original contents not replaced...
4.true...-> there is nothing called negative and positive zero in java.. all zeros are treated equally..

No comments:

Post a Comment

Please post your comments. Your comments make us to write more programs for you.