cs 105 quiz 3

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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


Kaugnay na mga set ng pag-aaral

Biochemistry CH6: DNA & Biotechnology

View Set

Last Computers in business review for exam 1

View Set

Gynecology Quiz: Contraception and Abnormal Bleeding

View Set

Chapter 66: Caring for Clients with Burns

View Set

Saunders Respiratory 182 Questions

View Set

Chemistry Chapter 12: Thermodynamics Study Guide

View Set