Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public class MainClass {
  2.  
  3. // 0 1 2 3 4 5 6 7 8 9
  4. // 10
  5. // 10 / 2 = 5
  6. // 5 - 1 = 4
  7. public static void main(String[] args) {
  8.  
  9. }
  10.  
  11. private static int[] changeByDomainLogic(int[] array) {
  12. if(checkIfArrayEven(array)) {
  13. array[0] = sumOfSecondPart(array);
  14. }
  15. return array;
  16. }
  17.  
  18. private static int sumOfSecondPart(int[] array) {
  19. int sum = 0;
  20. int mediumIndex = array.length / 2 - 1;
  21. for(int i = mediumIndex + 1; i < array.length; i++) {
  22. sum += array[i];
  23. }
  24. return sum;
  25. }
  26.  
  27. private static boolean checkIfArrayEven(int[] array) {
  28. if(array.length == 0) return false;
  29. return array.length % 2 == 0;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement