Programming and Problem Solving with Java

(やまだぃちぅ) #1

738


e.Overflowis the condition that occurs when the result of a calculation is greater
than the maximum number that can be represented in the computer.


  1. a. x is 2314.38
    b.x is 2,314.38
    c. x is 2314.4
    d.x is 2,314.383


Chapter 12 Programming Warm-Up Exercises
1.final intNUM_SCHOOLS = 10 ;
final intNUM_SPORTS = 3 ;
// row/column 0 is football; row/column 1 is basketball;
// row/column 2 is volleyball
int[][] kidsInSports = new int[NUM_SCHOOLS][NUM_SPORTS];
double[][] costOfSports = new double[NUM_SPORTS][NUM_SCHOOLS];
a.intmostSoFar = 0 ;
for(intcolumn = 1 ; column < NUM_SCHOOLS; column++)
if(costOfSports[ 0 ][column] > costOfSports[ 0 ][mostSoFar])
mostSoFar = column;
// mostSoFar is the school that spent the most on football
b.intwhichSport = 0 ;
intlast = NUM_SCHOOLS - 1 ;
for(introw = 1 ; row < NUM_SPORTS; row++)
if(costOfSports[row][last] > costOfSports[whichSport][last])
whichSport = row;
// whichSport contains the sport that the last school spent the
// most on
c. intmostStudents = 0 ;
for(introw = 1 ; row < NUM_SCHOOLS; row++);
if(kidsInSports[row][ 1 ] > kidsInSports[mostStudents][ 1 ])
mostStudents = row;
// mostStudents is the school with the most students playing
// basketball
d.intwhichSport = 0 ;
for(intcolumn = 1 ; column < NUM_SPORTS; column++)
if(kidsInSports[ 2 ][column] > kidsInSports[ 2 ][whichSport])
whichSport = column;
// whichSport is the sport that the third school has the most
// students in
e.intsum = 0 ;
for(intcolumn = 0 ; column < NUM_SCHOOLS; column++)
sum = sum + costOfSports[ 2 ][column];
// sum contains the total amount spent on volleyball
Free download pdf