Question
Consider the following Java code: public class
SubstringDryRun { Â Â public static void main(String[] args) { Â Â Â Â String s = "Programming"; Â Â Â Â String s1 = s.substring(3, 7); Â Â Â Â String s2 = s.substring(s.indexOf('g') + 1); Â Â Â Â System.out.println(s1 + s2); Â Â } } What will be the output of this program?Solution
Correct Answer: A s = "Programming" s1 = s.substring(3, 7): P-0, r-1, o-2, g-3, r-4, a-5, m-6, m-7, i-8, n-9, g-10. substring(3, 7) extracts characters from index 3 up to (but not including) 7. So, s[3]s[4]s[5]s[6] which is "gram". s.indexOf('g') is 3. s2 = s.substring(s.indexOf('g') + 1) is s.substring(3 + 1) which is s.substring(4). s.substring(4) extracts characters from index 4 to the end. So, s[4]s[5]s[6]s[7]s[8]s[9]s[10] which is "ramming". s1 + s2 = "gram" + "ramming" = "gramramming".
NPOP Programme is regulated by which ministry of India?
Which can help a producer in determining how much of a product is required to be produced?
………………………………… has become the first state in India to launch its own Climate Change Mission.
... Mendel is famous for
KRITAGYA -A National level Hackathon, organized by ICAR with NAHEP and Crop Science division is majorly focused on____.Â
In microwave oven microwaves are emitted by
Which of the following statement is incorrect for Cyclones?
Ferrous sulphate-heptahydrate contains:
Which of the following is disease causing pathogen in citrus group?
What are the symptoms of damage caused by the Brown Plant Hopper (BPH) in rice?