Menu
Question Index
...

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");
        }
    }
}


Art is the proper task of life - Matches art false
Art is the proper task of life - Matches life true
Art is the proper task of life - Matches Art true
Art is the proper task of life - Matches life true
Art is the proper task of life
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java regionMatches() Method - String Comparison

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App