Menu
Topics Index
...
`

Comparison


If you need explanation Read this topic

If you need Answer Take test on this topic

Comparison
What will be the output of the following program?
public class JavaCourse {
    public static void main(String[] args) {
        String course = "Java is my Course";
        String school = "Merit Campus is my school";
        String start = "java";
        String end = "School";
        boolean starts1 = course.startsWith(start);
        boolean starts2 = school.endsWith(end);
        System.out.println(school + " - name ends with " + end + "? " + starts1);
        System.out.println(course + " - name starts with " + start + "? " + starts2);
    }
}

A. Merit Campus is my school - name ends with School? true
Java is my Course - name starts with java? true
B. Merit Campus is my school - name ends with School? false
Java is my Course - name starts with java? false
C. Merit Campus is my school - name ends with School? false 
Java is my Course - name starts with java? true
D. Some other output
E. Compilation Error or Runtime Error
Topic: Java String startsWith() And endsWith() Methods

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 A as start and end string variable are matched it gives true and prints

Posted by Naga Sinst    2014-06-25 13:37:07


Ans: b
As the school and java have different case  than that of actual sentence thus method will return a falsr

Posted by Anmol Chopra    2014-06-25 13:42:39


Ans is is D..school os not ending with school n course is not starting with java..it starting with Java...both are false

Posted by Uday Kumar    2014-06-25 13:44:24


B is ans.as both starts1 and starts2 are false

Posted by Shabaaz Shaikz    2014-06-25 13:46:07


B

Posted by Shri Nandhitha    2014-06-25 14:31:47


B as java is case sensitive so J and j are not same.

Posted by Amit Sabat    2014-06-25 14:52:24


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

Posted by Merit Campus    2014-06-26 04:36:19


© meritcampus 2019

All Rights Reserved.

Open In App