for(int i = 0; i < 13; i++){
arr.add(0, arr.get(12));
//String d = arr.get(12);
//arr.remove(12);
//arr.add(0, d);
}
......>>>>
in above lines of code i used first statement inside loop and result was as per requirement......replacing of first element with the last.
then why add some extra lines( three commented statements inside loop above) to remove last element ?
my code is correct otherway but wrong another way>>>>>please help
Resolved
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Tayyab Mubeen
30 October 2018, 17:33
resolved it if you solve this question
0
kapil
31 October 2018, 05:00
ok boss
0
Khurram
30 October 2018, 11:57
the problem wants you to remove the last element and add it to index 0, so the list size should be the same when you finish the program, that is, 5
but if you add the elements using the first statement inside the loop, you are not removing any element, you just keep adding the 4th index element to the original list, if you check the size of the list it will be 18, not 5, because you have added 13 elements in this loop to the original list of 5 elements
0
kapil
30 October 2018, 15:39
sorry for giving wrong inputs...i actually tested it with 5 elements and before putting in here i forgot to adjust it, thats why it is 4 instead of 12.....
0