Java Reference
In-Depth Information
Write a test program that reads a 3-by-4 matrix and displays the sum of each
column. Here is a sample run:
Enter a 3-by-4 matrix row by row:
1.5 2 3 4
5.5 6 7 8
9.5 1 3 1
Sum of the elements at column 0 is 16.5
Sum of the elements at column 1 is 9.0
Sum of the elements at column 2 is 13.0
Sum of the elements at column 3 is 13.0
*8.2
( Sum the major diagonal in a matrix ) Write a method that sums all the numbers
in the major diagonal in an n
*
n matrix of double values using the following
header:
public static double sumMajorDiagonal( double [][] m)
Write a test program that reads a 4-by-4 matrix and displays the sum of all its
elements on the major diagonal. Here is a sample run:
Enter a 4-by-4 matrix row by row:
1 2 3 4.0
5 6.5 7 8
9 10 11 12
13 14 15 16
Sum of the elements in the major diagonal is 34.5
*8.3
( Sort students on grades ) Rewrite Listing 8.2, GradeExam.java, to display the
students in increasing order of the number of correct answers.
**8.4
( Compute the weekly hours for each employee ) Suppose the weekly hours for all
employees are stored in a two-dimensional array. Each row records an employ-
ee's seven-day work hours with seven columns. For example, the following
array stores the work hours for eight employees. Write a program that displays
employees and their total hours in decreasing order of the total hours.
Su
M
T
W
Th
F
Sa
Employee 0
2434588
Employee 1
7343344
Employee 2
3343322
Employee 3
9347341
Employee 4
3543638
Employee 5
3446344
Employee 6
3748384
Employee 7
6359279
8.5
( Algebra: add two matrices ) Write a method to add two matrices. The header of
the method is as follows:
public static double [][] addMatrix( double [][] a, double [][] b)
 
Search WWH ::




Custom Search