Menu
Topics Index
...
`

Venkatadri Express2169


If you need explanation Read this topic

If you need Answer Take test on this topic

Venkatadri Express2169
What will be the output of the following program?
public class Movie {
    public static void main(String[] args) {
        String data = "Venkatadri Express";
        String name = "Venkatadri";
        String train = "express";
        boolean nameStstus = data.regionMatches(true, 0, name, 5, name.length());
        boolean trainStstus = data.regionMatches(true, data.length() - train.length(), train, 0, train.length());
        System.out.print(name + "-" + nameStstus + "\n" + train + "-" + trainStstus);
    }
}

A. Venkatadri-false
express-true
B. Venkatadri-true
express-true
C. Venkatadri-false
express-false
D. Compilation Error or 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.

Ans is C...because the region name and train does not match with data in the given length for both

Posted by Badam Swathi    2014-04-30 03:52:12


Answer : C ..because
-> first regionMatches() we are trying to compare the   region name with data from the 5th location and hence it returns FALSE
-> Second regionMatches() returns TRUE because we are comparing the strings from the 11th , 0th location respectively and they match ( express )

Posted by Deepak Kumar Yadav    2014-04-30 04:01:31


option A. regionMatches tells if two string regions are equal or not. the nameStatus returns false since "tadri Express" is not equal to "Venkatadri" and trainStatus returns true as "Express" is equal to "express" ignoring the case, because of the ignore case argument.

Posted by Yashasvi Bandi    2014-04-30 04:10:26


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

Posted by Merit Campus    2014-05-01 07:00:57


© meritcampus 2019

All Rights Reserved.

Open In App