Computer Science 252
Problem Solving with Java

Fall 2015, The College of Saint Rose

Lecture 22: Arrays
Date: Thursday, November 19, 2015


Agenda

Lecture 22 Assignment

Due at the start of class, Tuesday, December 1.

Please submit answers to these questions either as a hard copy (typeset or handwritten are OK) or by email to terescoj AT strose.edu by the start of class. Please use a clear subject line when submitting by email (e.g., CSC 252 Lecture 22 Assignment , Joe Student). We will discuss these questions at the start of class, so no late submissions are accepted.

  1. Write a method that takes an array of double values as its parameter and returns the sum of all elements in the array. (4 points)
  2. What is printed by this program? (8 points)
    private void mystery() {
        int [] report = { 5, 4, 10, 4, 6, 3, 4 };
        int turn = 0;
        int shot = 0;
        int lastTotal = 0;
    
        while (shot < report.length && turn < 10) {
            int increment = report[shot] + report[shot+1];
            if (increment >= 10) {
                increment = increment + report[shot+2];
            }
            if (report[ shot] < 10) {
                shot++;
            }
            lastTotal = lastTotal + increment;
            shot++;
            turn++;
            System. out. println(shot + " : " + lastTotal);
        }
    }
    

Examples