Programming and Problem Solving with Java

(やまだぃちぅ) #1

624


b.int[][] exampleB;
exampleB = new int[ 4 ][ 3 ];
inti, j;
for(i = 0 ; i < 3 ; i++)
for(j = 0 ; j < 3 ; j++)
exampleB[i][j] = (i + j) % 3 ;
c. int[][] exampleC;
exampleC = new int[ 8 ][ 2 ];
inti, j;
exampleC[ 7 ][ 0 ] = 4 ;
exampleC[ 7 ][ 1 ] = 5 ;
for(i = 0 ; i < 7 ; i++)
{
exampleC[i][ 0 ] = 2 ;
exampleC[i][ 1 ] = 3 ;
}


  1. a.Define an intvariable teamTypeand an intvariable resultType.
    b.Define a two-dimensional array variable outcome.
    c. This array will be used to keep track of the wins and losses for a baseball
    season.teamTyperepresents the classes: freshman (0), sophomore (1), junior
    (2), and senior (3).resultTyperepresents the outcome for the team: won (0),
    tied (1), or lost (2). Instantiate an array object for the variable outcome.
    d.Write a code fragment that increases the number of freshman wins by 1.
    e.Write a code fragment that determines which class won the most games.
    f. Write a code fragment that determines the total number of wins for all
    classes.
    4.The number of rows in the array must be specified on the parameter list of a
    method that takes the array as a parameter. (True or False?)
    5.Declare and instantiate the two-dimensional arrays described below.
    a.An array with five rows and six columns that contains booleanvalues
    b. An array, indexed from 0 through 39 and 0 through 199, that containsdoubleval-
    ues
    c. An array, indexed from 0 through 3 and 0 through 2, that contains char
    values

Free download pdf