/*
* Code written in java
* Just copy and paste the code to run
* Read in line comments for better understanding
*/
import java.util.ArrayList;
import java.util.Arrays;
public class Solution {
/*
* countFours function is used to print the number of 4s
* in the list of integers
*/
public static void countFours(ArrayList a) {
//here list ‘a’ is a dynamic array whose value
//can be changed in run time
int count = 0;
for(int i=0; i a = new ArrayList(Arrays.asList(1, 3, 9, 91, 40, 4, -5, 100, 20, -23));
System.out.println(“The array is: “);
for(Integer i : a) {
System.out.print(i + ” “);
}
//call the function countFours() to display
//the number of integers divisible by 4
countFours(a);
//Now lets change the content of list of integers
//Adding new elements to the list
a.add(44);
a.add(-8);
//changing the integer 40 to 39
a.set(4, 39); //changing the element at index 4 to 39
System.out.println(“nThe new array after modifications is: “);
for(Integer i : a) {
System.out.print(i + ” “);
}
//now, lets call countFours() again
//it should display 6 now (4, 100, 20, 44, -8)
countFours(a);
}
}
“Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!”
What Students Are Saying About Us
.......... Customer ID: 12*** | Rating: ⭐⭐⭐⭐⭐"Honestly, I was afraid to send my paper to you, but splendidwritings.com proved they are a trustworthy service. My essay was done in less than a day, and I received a brilliant piece. I didn’t even believe it was my essay at first 🙂 Great job, thank you!"
.......... Customer ID: 14***| Rating: ⭐⭐⭐⭐⭐
"The company has some nice prices and good content. I ordered a term paper here and got a very good one. I'll keep ordering from this website."