From now on, green eggs and ham will be overshadowed by lists. Or would the opposite be better? Here's our task: add some of Dr. Suess's famous words to a list: "Sam", "I", "Am". After each word, we'll insert "Ham" into the list. And display the result on the screen. Each list element on a new line.
More Sam-I-Am
- 5
Locked
Comments (12)
- Popular
- New
- Old
You must be signed in to leave a comment
Hemel
2 September 2021, 12:05
Is there a better way to do this than manually placing each "Ham" into the list?
Could it be written into a for loop for example?
0
Pranai Rao Head of Software at FTC Team 8888
26 November 2022, 15:12
Yes there is:
0
ImDevin
21 April 2021, 00:33
although the following is acceptable way to do it, it doesn't pass. FYI,
ArrayList<String> list = new ArrayList<>(Arrays.asList("Sam", "I", "Am"));
+1
Nickolas Johnson
26 March 2020, 14:34
Seeing as the instructions are unclear, you have to enter each word individually and only use one ArrayList for the "Declare a string list variable and immediately initialize it" to work.
This exercise is more about showing that you can dynamically insert words between other words in an ArrayList. Don't do what I did and spend 45 minutes overcomplicating it for it to run correctly but still not pass verification.
0
Kent Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
15 November 2019, 03:14
Verifier does not like this: ArrayList<String> list = new ArrayList<>(Arrays.asList("Sam","I","Am"));
0
dabay wang Backend Developer at Amazon
24 March 2020, 16:37
It wants you add one by one... unfortunately.
0
KIN SOCHEAT
29 May 2019, 23:30
Someone can display the correct result: all below is wrong...
0 Sam
1 Ham
2 I
1 Ham
4 am
1 Ham
_____________________
1 Ham
4 Am
1 Ham
2 I
1 Ham
0 Sam
+1
Roman
30 May 2019, 06:32
am != Am (first result)
+2
thisisalongname
2 May 2019, 02:41
This one could do with the example output, as I first created a code which output:
SamHam
IHam
AmHam
which was actually more challenging to do than the intended output.
0
Arko Sarkar
31 August 2018, 15:22
Should the output be:
Sam
Ham
I
Ham
Am
Ham
OR
SamHam
IHam
AmHam
?
0
Roman
3 September 2018, 05:45
+5
Alexey
23 March 2019, 16:44
Thanks
0