Let's create not one, but two arrays at the same time! One will be a refuge for 10 numbers, while the other will be a haven for 10 strings. Use the keyboard to populate an array of strings. In each element of the number array, record the length of the string whose string array index coincides with the current index of the number array. Then display the contents of the number array on the screen, and you're done.
Lonely arrays interact
- 5
Locked
Comments (10)
- Popular
- New
- Old
You must be signed in to leave a comment
Ice_ Beam
25 June 2021, 18:33
nice I solved this with inputs, 1 for loop and for each loop!
I guess everyone has their code preference style!
0
OBINNA
6 May 2021, 18:45
stuck a lil on this one
found out
array.length - length of an array
n.length() - length of a string n.
nice
0
Rebekah H
23 July 2020, 00:00
what is the output suppose to look like on this task?
+1
Roman
24 July 2020, 06:00
For example
input :
grandfather
grandmother
father
mother
son
daughter
cat
dog
program
car
Output :
11
11
6
6
3
8
3
3
7
3
because :
the length of the string "grandfather" is 11
the length of the string "grandmother" is 11
the length of the string "father" is 6
the length of the string "mother" is 6
the length of the string "son" is 3
the length of the string "daughter" is 8
the length of the string "cat" is 3
the length of the string "dog" is 3
the length of the string "program" is 7
the length of the string "car" is 3
+2
Rebekah H
26 July 2020, 02:52
thank you :)
0
Ice_ Beam
25 June 2021, 18:33
this helped a lot thanks!
0
Kent Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
2 November 2019, 00:04
I failed the last requirement of displaying the string lengths using this technique:
System.out.println(Arrays.toString(listReference));
which outputs: [1, 2, 3, 4, 5, 4, 3, 2, 1, 1] or whatever the string lengths are
I suppose they maybe want each length on a new line, so I will try that using println
0
Kent Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
2 November 2019, 00:14
that worked
0
Tonatiuh
30 October 2019, 21:19
There is a little difference in how to get the length of one array and the length of one array's element:
+4
Kyle Chatman
21 May 2019, 17:14
Note the verification requires the string array size to be hard coded as "10". A variable with value ten works but is not accepted. They're fine with the int array size being given via variable.
+1