Implement a static main(String[]) method that populates the array variable with the values valueStart and valueEnd.
If the length of the array is even, then its first half must be filled with valueStart values, and the second half with valueEnd.
If the length of the array is odd, then fill the large
Filling an array
- 6
Locked
Comments (10)
- Popular
- New
- Old
You must be signed in to leave a comment
@amsilla FullStack Developer at Amsilla, Inc
31 January 2025, 20:35
For the odd case, the larger part is the first case (). So, in an array of 5, it would be: if valueStart is 1, and valueEnd is 2.
0
Tomasz Enyeart
2 February 2024, 18:41
the requirements for this task are really bad "Requirements:
• Implement the main(String[]) method in accordance with the task conditions." the requirments are litterally telling you toi just follow the instructions instead of explain how the instructions need to be followed to complete the task. this needs to be changed
0
SvenskKung
31 October 2023, 04:55
This task is worded pretty terribly for the odd number part. The intended meaning is fill half of the length + 1 with valueStart, and the second half with valueEnd. Just saying, "fill the larger part" is nonsensical because you can literally make either side larger...because it's odd...
0
sl33pr Backend Developer at Church of Jesus Chri
20 September 2023, 17:32
Keep in mind that the array.length value is taken at face value if used for the first index, but evaluates to array.length -1 when used for the second index. That's not confusing at all!
As mentioned in other posts, this statement is poorly written: "If the length of the array is odd, then fill the larger part with valueStart, and the smaller one with valueEnd."
It should read something like, if the array is odd, split the array length in half and add one. Fill that number of indexes with valueStart at the beginning of the array, and fill the remaining indexes with valueEnd.
+1
Hiyo Full Stack Developer
17 January 2023, 07:38
HUH?? ![]()
+1
Vadim “迪姆哥”
12 October 2022, 19:43
Please correct the validator of the code!
This task could be past only if:
When array size is odd, startValue must fill by array.length +1;
As the task requires:
When array size is odd, fill LARGER part with valueStart!
For example, if I try to fill first part of array with valueStart by "array.length * 0.8" (80% of array) - which technicly is larger part,
validator didn't give it pass....
0
Ace Phelps
30 April 2022, 07:36
idk whats going on but heres my code what did i do wrong i dont get it
if (array.length % 2 == 0) {
Arrays.fill(array, 0, array.length/2, 10);
Arrays.fill(array, array.length/2, array.length, 13);
System.out.println(Arrays.toString(array));
}
if (array.length % 2 != 0) {
Arrays.fill(array, 0, array.length, 13);
Arrays.fill(array, array.length/2, array.length, 10);
System.out.println(Arrays.toString(array));
}
+1
Ace Phelps
30 April 2022, 07:36
Error:
Implement the main(String[]) method in accordance with the task conditions.
0
Ace Phelps
30 April 2022, 07:50
ok i was confused by second step about larger part now i got it (larger part is more then half)
0
Lisa
9 January 2022, 09:22
I do not know the task and I can not open its description. If you're looking for answers the best way is, to attach your existing code. That way everyone can read the task description and what you came up with so far.
0