MCQModerate1 mark
1
Choose the correct answers to the questions from the given options. (Do not copy the questions, write only the correct answers.)
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.
Topic: substring() with two arguments
Previous-year question practice database
Try it
Pick an option and check your answer. The full worked answer is below either way.
Answer
Exam answer
(a) 6.
Explanation
Index the word first: A=0, C=1, K=2, N=3, O=4, W=5, L=6. The extract starts at index 3 (N). The second argument of substring(a, b) is the index just AFTER the last character wanted — it is exclusive. The last wanted character is W at index 5, so the second argument is 6. A quick check: the length of the extracted text equals b - a, and NOW has 3 letters, so 6 - 3 = 3 confirms it.
In words
6.
More from String Manipulation
String a[] = {"Atasi", "Aditi", "Anant", "Amit", "Ahana"};
System.out.println(a[1].charAt(1) + "*" + a[2].charAt(2));
The output of the above statement is:2026Which of the following String methods returns a negative value?2026Assertion (A): The substring() method modifies the original String.
Reason (R): The substring() method can extract part of a String starting from a specific index.2026Give the output of the following program segment:
String S = "GRACIOUS".substring(4);
System.out.println(S);
System.out.println("GLAMOROUS".endsWith(S));2026Name the following:
(a) The return data type of the method equals().
(b) The String method which has no parameter and returns a String.2026Write a program to accept a word and print the Symbolic of the accepted word.
Symbolic word is formed by extracting the characters from the first consonant, then add characters before the first consonant of the accepted word and end with "TR".
Example: AIRWAYS - Symbolic word is RWAYSAITR
BEAUTY - Symbolic word is BEAUTYTR2026