Loading...
Loading...
Loading...
A class list is full, and m late admissions arrive. Make a new, longer list that keeps every old name and adds the new ones at the end. The old list must stay exactly as it was.
Old list (<n>): <names> and New list (<n + m>): <names>, names separated by single spaces.Example
Input
3 Asha Ravi Imran 1 Zoya
Output
Old list (3): Asha Ravi Imran New list (4): Asha Ravi Imran Zoya
Arrays.copyOf(names, 4) keeps the three names and leaves one empty slot for Zoya.
Try the problem first. Open one hint at a time.
Arrays.copyOf(names, n + m) makes the longer array and copies the old names into it.
Fill the new slots from index n to n + m - 1.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor