Write a function change that accepts an array integers and its size as parameters it divides all array elements by 5 that are divisible by 5 and multiplies other array element by 2.
Answers
Answer:
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
int array[] = {1,2,3,4,5,6,7,8,9,10};
function(array,10);
}
public static String function(int[] array,int size){
size= array.length;
int remainder = 0;
ArrayList<Integer> div5 = new ArrayList<Integer>();
ArrayList<Integer> mulby2 = new ArrayList<Integer>();
for(int i=0;i<size;i++){
remainder = array[i] %5;
if(remainder==0){
div5.add(array[i]/5);
}
else{
mulby2.add(array[i]*2);
}
}
System.out.println("Elements that are Divided by 5");
for (int i : div5) {
System.out.println(i);
}
System.out.println("\t \nElements that are Multiplied by 2");
for (int i : mulby2) {
System.out.println(i);
}
return "Done";
}
}
Explanation: