CHAPTER 7 - Java Software Solutions, 4e Chapter 7...

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

View Full Document Right Arrow Icon
Java Software Solutions, 4e Lewis/Loftus Chapter 7 Chapter 7 Exercise Solutions 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; “[]” is missing float elapsedTimes[] = {11.47, 12.04, 11.72, 13.88}; valid; the “[]” can be placed either after the element type (“float”) or after the reference variable (“elapsedTimes”) int[] scores = int[30]; invalid; the right hand side of the assignment operator must contain either an initializer list or an expression of the form, “new int[30]” 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 char grades[] = {'a', 'b', 'c', 'd', 'f'}; valid; the assignment is correct Java syntax char [] grades = new char[]; invalid; the size of the array must be indicated when the array is instantiated. Changing the right half of the statement to "new char[SIZE];", for example, would make the statement valid. 7.2 Describe five programs that are difficult to implement without using arrays. 1.) a program to find the average midterm score of 600 students enrolled in an introductory computer science course 2.) a program to record and compute the sum of the snowfalls, recorded on a daily basis for the 40 days preceding the 2002 Winter Olympics
Background image of page 1

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

View Full DocumentRight Arrow Icon
Java Software Solutions, 4e Lewis/Loftus Chapter 7 3.) a program to determine the relative frequency of each character in the Cyrillic alphabet in the original version of The Brothers Karamasov 4.) a program to compute the mean and standard deviation of the Dow Jones Industrial Average closings since September 11 5.) a program to store the coordinates of the vertices of polygons approximating the surface of a beating heart 7.3 Describe what problem occurs in the following code. What modifications should be made to it to
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

CHAPTER 7 - Java Software Solutions, 4e Chapter 7...

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

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