Week 11 rogi Exam 2 3 Methods ill in the following Example ts are provided in th
ID: 3701756 • Letter: W
Question
Week 11 rogi Exam 2 3 Methods ill in the following Example ts are provided in the provided so they run according to their specifications 6. (6 points) evensTozero: Given an array of integers, change all the even integers in the array to 0. I (1,2,3,4,5 >(1,0,3,0,5 II (74,3,4,2,74,75,2} (,3,e,0,0,75,0 public static void evensToZero(int[] arr) t 7. (10 points) sumofTens: Given a two dimensional array of integers, return the sum of all the integers in the array that are multiples of 10. // {(10,5,4.10), ' {74, 75,80)}-.-10? /I ti-10, 50, 17)) r) ( public static int sumof(inExplanation / Answer
Methods.java
import java.util.Arrays;
public class Methods {
public static void main(String[] args) {
int arr[] = {1,2,3,4,5};
evensToZero(arr);
int a[][] = {{1,2,3,10},{30,20}};
System.out.println("Sum: "+sumOfTens(a));
}
public static void evensToZero(int[] arr) {
for(int i=0;i<arr.length;i++) {
if(arr[i] % 2 == 0)
arr[i]= 0;
}
System.out.println("Array elements: ");
System.out.println(Arrays.toString(arr));
}
public static int sumOfTens(int[][] arr) {
int sum = 0;
for(int i=0;i<arr.length;i++) {
for(int j=0;j<arr[i].length;j++) {
if(arr[i][j] % 10 == 0)
sum+=arr[i][j];
}
}
return sum;
}
}
Output:
Array elements:
[1, 0, 3, 0, 5]
Sum: 60
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.