Computer Applications
What will be the output of following code?
String c = "Hello i love java";
boolean var;
var = c.startsWith("hello");
System.out.println(var);
- true
- false
- 0
- 1
Answer
false
Reason — An important point to note in this code is that startsWith() method in Java is case-sensitive, meaning it will differentiate between uppercase and lowercase characters. In this case, the prefix "hello" starts with a lowercase 'h', but the string in c starts with an uppercase 'H'. Since the cases don't match, the startsWith() method will return false. So var will be assigned false and given as output.
Related Questions
A single dimensional array contains N elements. What will be the last subscript?
- N
- N - 1
- N - 2
- N + 1
Identify the output of the following code :
String P = "20", Q = "19"; int a = Integer.parseInt(P); int b = Integer.valueOf(Q); System.out.println(a + "" + b);- 2019
- 39
- 20
- 19
A string function which removes the blank spaces provided in the prefix and suffix of a string.
- String.trim()
- String.ltrim()
- String.rtrim
- String.strim
Assertion (A) Identifier is a name given to a package, class, interface, method or variable.
Reason (R) Identifier allows a programmer to refer to the item from other places in the program.- Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
- Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A).
- Assertion (A) is true and Reason (R) is false.
- Assertion (A) is false and Reason (R) is true.