Imagine people making appointments at a dental office where the waiting list acts like a stack rather than a queue: the last person to schedule is the first to have a drill taken to his or her tooth. We'll write a program that reflects this unusual situation: create a list and add 10 strings, but we'll add them to the beginning of the list rather than the end.
To the top of the list
- 2
Locked
Comments (16)
- Popular
- New
- Old
You must be signed in to leave a comment
Usman Full Stack Developer at QA
5 July 2021, 12:27
im acc laughing (cryinng) at the fact that i spent so long on this 😂😂😂. i was complicating this so much haha.
Hint -
-dont over complicate it
-look at the .add() method
+1
Hoist
6 January 2022, 19:31
https://codegym.cc/tasks/com.codegym.task.task07.task0710
0
Khongpak Phupkdee
16 April 2021, 02:02
The program should add lines to the beginning of the list.
What does "add lines" mean?
0
ImDevin
19 April 2021, 04:08
it just means to add the new string to the beginning of the list
+1
Yamini Krishna
25 March 2021, 01:06
Can I know what is wrong in my code, that the test is failing
ArrayList<String> strings = new ArrayList<String>();
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
for(int i=0; i<10;i++){
strings.add(i,r.readLine());
System.out.println(strings.get(i));
}
0
Roman
26 March 2021, 06:59
Please post your question with the attached solution in the section Help.
0
Samuel
3 April 2021, 18:02
Hi Yamini, I am sure that you have already solved this task, but to make it easier you should have a loop to add the strings from the keyboard and a loop to print the strings. You can take out System.out.println(strings.get(i)) from the for loop and put it in a FOR EACH LOOP.
0
Hoist
6 January 2022, 19:32
https://codegym.cc/tasks/com.codegym.task.task07.task0710
0
David Haines
14 July 2020, 03:08
I'm beginning to get a bit irritated with java. in general.
I had originally coded this (and verification failed miserably):
list.add (0, s);
After 30-40 minutes of trying to determine why, I somehow managed to remove the space between list.add and (0,s) without realizing it, and tried one more time and everything was fine.
Can someone explain to me why no space in between works but having a single space in between doesn't?
0
Roman
14 July 2020, 06:40
Has the test failed with a space or the code did not work? Send this code in PM
0
Devonte A
28 May 2020, 14:54
Consider that when you add an element to a position/index in an array it will shift the elements 1 to the right e.g. adding to index 1 will push the element at index 1 to index 2 and the new inserted element will be at index 1. :)
0
rishabh
13 November 2019, 07:21
whats wrong in my code..
2nd and 3rd requirement are not fulfilled.
0
Roman
14 November 2019, 06:41
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
0
Bhavishya Samriya
11 July 2019, 07:01
what is wrong with my code
0
Roman
12 July 2019, 06:43
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
+2
Bhavishya Samriya
13 July 2019, 04:50
Thank you
But I figured it out.
There was a mistake in the placement of zero in list.add();
0