Chap07 EX Solutions

Chap07 EX Solutions - Java Software Solutions, 6th Edition...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Software Solutions, 6 th Edition Exercise Solutions, Ch. 7 Chapter 7 Exercise Solutions EX 7.1. Which of the following are valid declarations? Which instantiate an array object? Explain your answers. int primes = {2, 3, 4, 5, 7, 11}; Invalid; an int cannot be declared and initialized using an intializer list. The brackets are missing. float elapsedTimes[] = {11.47, 12.04, 11.72, 13.88}; Valid; the brackets can be placed either after the element type or after the reference variable. However, this is not the preferred technique. This declaration creates an array object. int[] scores = int[30]; Invalid; the right hand side of the assignment operator must contain either an initializer list or a new operation. int[] primes = new {2,3,5,7,11}; Invalid; “new” on the right hand side of the assignment operator is neither necessary nor acceptable. int[] scores = new int[30]; Valid; the assignment is correct Java syntax. This declaration creates an array object. char grades[] = {'a', 'b', 'c', 'd', 'f'}; Valid; the brackets can be placed either after the element type or after the reference variable. However, this is not the preferred technique. This declaration creates an array object. char[] grades = new char[]; Invalid; the size of the array must be indicated when the array is instantiated. EX 7.2. Describe five programs that would be difficult to implement without using arrays. A program to find the average midterm score of 600 students enrolled in an introductory computer science course. A program to record and compute the sum of the snowfalls, recorded on a daily basis for the 40 days preceding the Winter Olympics. A program to determine the relative frequency of each character in the Cyrillic alphabet in the original version of The Brothers Karamasov. A program to compute the mean and standard deviation of the Dow Jones Industrial Average closings since September 11, 2001. A program to store the coordinates of the vertices of polygons approximating the surface of a beating heart. EX 7.3.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Chap07 EX Solutions - Java Software Solutions, 6th Edition...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online