0

Code

Public class my{ Public Static void main(String []args){ String g= “Hello i love java”; Int start=2; Int end=9; Char s[ ]=new char[end-start]; g.getchars(start,end,s,0); }} Output is: llo i l Iam not understanding why ?

14th May 2020, 4:04 PM
Haritha Vuppula
Haritha Vuppula - avatar
4 Answers
+ 1
s is an array of 7 characters. with g.getchars() method, s is assigned to the characters of g index ranging from start to end. in the output first 'l' corresponds to the char with index 2 in g, same way, last 'l' corresponds to the char with index 8.
14th May 2020, 4:19 PM
Mustafa K.
Mustafa K. - avatar
0
it copies chars form position 2 to 9 (except 9) String g = "He llo I l ove java"; // 01 2345678 90123456 public class my { public static void main(String []args){ String g = "Hello I love java"; int start =2; int end =9; char[] s = new char[end-start]; g.getChars(start, end, s, 0); System.out.println( s ); } }
14th May 2020, 4:30 PM
zemiak
0
from g.getchars(start,end,s,0); how we get llo i l ??
14th May 2020, 4:32 PM
Haritha Vuppula
Haritha Vuppula - avatar
0
Indian explanation is already given by @zemiak. From string g, it copies charecters from start index (2) to end-1 (9-1=8, end not inclusive) index.. into the s charecter array...
14th May 2020, 5:26 PM
Jayakrishna 🇼🇳