Computer Applications
To extract the word NOW from the word "ACKNOWLEDGEMENT", the Java statement "ACKNOWLEDGEMENT".substring(3, ...............) is used.
Choose the correct number to fill in the blank.
- 6
- 7
- 5
- 8
Java String Handling
2 Likes
Answer
7
Reason — The method substring(beginIndex, endIndex) extracts characters from the starting index up to (but not including) the ending index. In "ACKNOWLEDGEMENT", the word "NOW" starts at index 3 (N) and ends at index 5 (W). Since the ending index is exclusive, we use 6 + 1 = 7 to include index 5. Hence, substring(3, 7) correctly extracts "NOW".
Answered By
1 Like
Related Questions
Assertion (A): The result of the Java expression 3 + 7/2 is 6.
Reason (R): According to the hierarchy of operators in Java, addition is done first followed by division.
- (A) is true and (R) is false.
- (A) is false and (R) is true.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
What is the type of parameter to be given for the method parseInt()?
- double
- String
- char
- int
The output of the below statement is:
String a[] = {"Atasi", "Aditi", "Anant", "Amit", "Ahana"}; System.out.println(a[1].charAt(1) + "*" + a[2].charAt(2));- da
- d*a
- ti
- t*i
Which of the following String methods returns a negative value?
- length()
- equals()
- compareTo()
- charAt()