+ 1
How to Add two Arrays of 5 integers and print the sum of the two using Java ?
6 Réponses
+ 1
Add this to your code:
for(int i = 0; i < arr1.length; i++){
System.out.print(arr1[i] + arr2[i]);
if(i != arr1.length - 1){
System.out.print(", ");
}
}
+ 2
Thank You and Congrats to you Z.K for the correct answer. You've got it!
+ 1
For example:
int arr1[ ] = { 1,2,4,5,6 };
int arr2[ ] = { 2,3,5,6,2 };
Output:
3, 5, 9, 11, 8
Question :
How to Add Two Arrays of 5 integers and print the sum of the two arrays using Java?
Let me share and show here your own answer guys. Who can answer? Let's doing it in here. Thank you!
+ 1
public class AddingTwoArraysIntegers
{
public static void main(String[] args) {
int arr1[] = {1,2,3,4,5,6,7,8,9,10};
int arr2[] = {2,3,4,5,6,7,8,9,2,3};
for (int i=0; i<arr1.length; i++){
if (i!=arr1.length){
System.out.println("The sum of two arrays integers are:");
System.out.println(arr1[i] + arr2[i]);
}
}
}
}
0
please show attempt.
you already know arrays and iterating them.
It is 80% of this.
0
for loop from 0 to 4 and add
arr1[i] and arr2[i].