Menu
Topics Index
...
`

Quote


If you need explanation Read this topic

If you need Answer Take test on this topic

Quote
What will be the output of the following program?
public class Quote {
    public static void main(String[] args) {
        String name = "Art is the proper task of life";
        String art = "Art";
        String life = "life";
        boolean artMatch = name.regionMatches(0, art, 0, art.length());
        boolean lifeMatch = name.regionMatches(name.length() - life.length(), life, 0, life.length());
        if (artMatch) {
            System.out.println(name + " - Matches " + art + " " + artMatch);
            System.out.println(name + " - Matches " + life + " " + lifeMatch);
        } else if (lifeMatch) {
            System.out.println(name + " - Matches " + art + " " + artMatch);
            System.out.println(name + " - Matches " + life + " " + lifeMatch);
        } else {
            System.out.println("Art is the proper task of life");
        }
    }
}

A. Art is the proper task of life - Matches art false
Art is the proper task of life - Matches life true
B. Art is the proper task of life - Matches Art true
Art is the proper task of life - Matches life true
C. Art is the proper task of life
D. Compilation Error
E. Runtime Error
Topic: Java regionMatches() Method - String Comparison

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

answer is B
as regionmatches returns true value for both the cases and as artMatch is true it prints accordingly..

Posted by Sasikanth Sharma    2014-08-07 08:51:59


answer is b life match is true

Posted by Shiva Goud    2014-08-07 08:52:25


Ans is B.
because both artMatch and lifeMatch are true. so the if block executes.

Posted by Gopinath Manchikanti    2014-08-07 08:54:46


answer is B

Posted by Ramya Reddy Addulla    2014-08-07 10:49:12


B...... when comparing region matches for artmatch it returns true(3==3),then  doing minus from length of nam to length of life  gives integer value so this can be considered as true.......both are true so both if block execute consequently.........

Posted by Arul Palanisamy    2014-08-08 02:32:28


Congratulations Sasikanth Sharma. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-08 04:31:35


© meritcampus 2019

All Rights Reserved.

Open In App