Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Write a method that accepts two arrays of M and adds the array element.docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité

Consultez-les par la suite

1 sur 1 Publicité

Write a method that accepts two arrays of M and adds the array element.docx

Télécharger pour lire hors ligne

Write a method that accepts two arrays of M and adds the array elements: Int[] a= {3,4,5,6,7,8,9,9} Int[] b = {9,8,7,8,7,8,7,9} The call to the method: add(a, b) should return an array with the following content: { 3,3,3,5,5,7,7,8}
Solution
class ArrayArithmetic { public static void main ( String[] args ) { int[] arrA = { 3,4,5,6,7,8,9,9}; int[] arrB = { 9,8,7,8,7,8,7,9}; int[] add = { 0,0,0,0,0,0,0,0}; for(int i = 0; i < arrA.length - 1; i++) { for(int j = 0; i < arrB.length - 1; i++) { add[i] = arrA[i] + arrB[i]; } } System.out.println(\"sum: \" + add[0]+\",\" + add[1] + \",\" + add[2] + \",\" + add[3]+\",\" + add[4] + \",\" + add[5] + \",\" + add[6] + \",\" + add[7]); } }
.

Write a method that accepts two arrays of M and adds the array elements: Int[] a= {3,4,5,6,7,8,9,9} Int[] b = {9,8,7,8,7,8,7,9} The call to the method: add(a, b) should return an array with the following content: { 3,3,3,5,5,7,7,8}
Solution
class ArrayArithmetic { public static void main ( String[] args ) { int[] arrA = { 3,4,5,6,7,8,9,9}; int[] arrB = { 9,8,7,8,7,8,7,9}; int[] add = { 0,0,0,0,0,0,0,0}; for(int i = 0; i < arrA.length - 1; i++) { for(int j = 0; i < arrB.length - 1; i++) { add[i] = arrA[i] + arrB[i]; } } System.out.println(\"sum: \" + add[0]+\",\" + add[1] + \",\" + add[2] + \",\" + add[3]+\",\" + add[4] + \",\" + add[5] + \",\" + add[6] + \",\" + add[7]); } }
.

Publicité
Publicité

Plus De Contenu Connexe

Plus par drosa1 (20)

Publicité

Write a method that accepts two arrays of M and adds the array element.docx

  1. 1. Write a method that accepts two arrays of M and adds the array elements: Int[] a= {3,4,5,6,7,8,9,9} Int[] b = {9,8,7,8,7,8,7,9} The call to the method: add(a, b) should return an array with the following content: { 3,3,3,5,5,7,7,8} Solution class ArrayArithmetic { public static void main ( String[] args ) { int[] arrA = { 3,4,5,6,7,8,9,9}; int[] arrB = { 9,8,7,8,7,8,7,9}; int[] add = { 0,0,0,0,0,0,0,0}; for(int i = 0; i < arrA.length - 1; i++) { for(int j = 0; i < arrB.length - 1; i++) { add[i] = arrA[i] + arrB[i]; } } System.out.println("sum: " + add[0]+"," + add[1] + "," + add[2] + "," + add[3]+"," + add[4] + "," + add[5] + "," + add[6] + "," + add[7]); } }

×