Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public class MainClass {
  2.  
  3. public static void main(String[] args) {
  4. int[] array = {12, 14, 14, 89, 11, 10};
  5. int[] resultArray = changeByDomainLogic(array);
  6. for(int i = 0; i < resultArray.length; i++) {
  7. System.out.print(array[i] + " ");
  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 ;
  21. for(int i = mediumIndex; 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