Filling an array

  • 6
  • Locked
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
You can't complete this task, because you're not signed in.
Comments (6)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Hiyo Full Stack Developer
17 January, 07:38
If the length of the array is odd, then fill the larger part with valueStart, and the smaller one with valueEnd.
HUH??
Vadim “迪姆哥”
Level 26 , Kazakhstan
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....
Ace Phelps
Level 9 , United States of America, United States
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)); }
Ace Phelps
Level 9 , United States of America, United States
30 April 2022, 07:36
Error: Implement the main(String[]) method in accordance with the task conditions.
Ace Phelps
Level 9 , United States of America, United States
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)
Lisa
Level 41
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.