cs 105 quiz 3
What is the value of the count variable after the execution of the given code snippet? ArrayList<Integer> num = new ArrayList<Integer>(); num.add(1); num.add(2); num.add(1); int count = 0; for (int i = 0; i < num.size(); i++) { if (num.get(i) % 2 == 0) { count++; } }
1
Which one of the following is true about the check method in the given code snippet? public static void check(ArrayList<Integer> chknum1) { int cnt = 0; for(int i = 0; i < chknum1.size(); i++) { if(chknum1.get(i) == 0) { cnt++; } } System.out.println("The total 0 values in the list are: " + cnt); }
The check method counts all the elements with value 0 in an array list passed as a parameter to the method.
Which one of the following descriptions is correct for the given code snippet? ArrayList<Integer> list1 = new ArrayList<Integer>(); ArrayList<Integer> list2 = new ArrayList<Integer>(); . . . int count = 0; for (int i = 0; i < list1.size() && i < list2.size(); i++) { if (list1.get(i) == list2.get(i)) { count++; } }
The code snippet compares the values of two array lists and stores the count of total matches found.
Java 7 introduced enhanced syntax for declaring array lists, which is termed
diamond syntax