The document describes a Java function that takes an ArrayList as a parameter, iterates through it, counts the number of single digit positive numbers, and returns the total count. It provides an example implementation that passes an ArrayList containing various numbers to the getSinglDigitCount method, which counts the single digits and prints the total of 4.
Create the Java function to receive an ArrayList object. The functio.pdf
1. Create the Java function to receive an ArrayList object. The function will count all of the single-
digit positive numbers in the array and return that total.
Solution
CountSingleDigit.java
import java.util.ArrayList;
public class CountSingleDigit {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(11);
list.add(112);
list.add(1);
list.add(1441);
list.add(1155);
list.add(6);
list.add(81);
list.add(8);
list.add(3);
list.add(111111);
int count = getSinglDigitCount(list);
System.out.println("Count = "+count);
}
public static int getSinglDigitCount(ArrayList list){
int count = 0;
for(int i=0; i=0 && list.get(i) <= 9){
count++;
}
}
return count;
}
}
Output: