Created
September 23, 2014 22:14
-
-
Save OlgaKulikova/b13204482afd97b6ac7d to your computer and use it in GitHub Desktop.
Lesson6_3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.Lesson6; | |
//Дано 3 массива чисел. С помощью 1-2-х циклов найти сумму элементов во всех массивах. | |
public class Lesson6_3 { | |
public static void main(String[] args) { | |
int[] first = new int[] {1, 3, 5, 7, 9}; | |
int[] second = new int[] {2, 4, 6, 8, 10, 12}; | |
int[] third = new int[] {5, 10, 15}; | |
int sum = 0; | |
int max = Math.max(first.length, second.length); | |
int absMax = Math.max(third.length, max); | |
for (int i = 0; i < absMax ; i++) { | |
if (i < first.length) { | |
sum += first[i]; | |
} | |
if (i < second.length) { | |
sum += second[i]; | |
} | |
if (i < third.length) { | |
sum += third[i]; | |
} | |
} | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment