Intro to Java Programming Comprehensive Version 10th Edition Test Bank
Intro to Java Programming Comprehensive Version 10th Edition Test Bank
Solution:
Part I:
0
8.0
6
false
16
9
43
943 is odd
0
Part II:
1.
import java.util.Scanner;
public class P1 {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("Enter the exchange rate from dollars to RMB: ");
    double rate = input.nextDouble();
        if (conversionType == 0) {
          System.out.print("Enter the dollar amount: ");
          double dollars = input.nextDouble();
          double RMB = dollars * rate;
          System.out.println("$" + dollars + " is " + RMB + " Yuan");
        }
        else if (conversionType == 1) {
          System.out.print("Enter the RMB amount: ");
          double RMB = input.nextDouble();
          double dollars = RMB / rate;
          System.out.println(RMB + " Yuan" + " is " + "$" + dollars);
        }
        else {
          System.out.println("Incorrect input");
        }
    }
}
2.
import java.util.Scanner;
        if (number % 5 == 0)
          System.out.print("HiFive");
                                                                                        1
         if (number % 2 == 0 || number % 3 == 0)
           System.out.println(" Georgia");
     }
}
Part III:
1. The expression (int)(76.0252175 * 100) / 100 evaluates to _________.
a. 76
b. 76.0252175
c. 76.03
d. 76.02
Key:a
#
2.          What is y after the following switch statement?
         int x = 0;
         int y = 0;
         switch (x + 1) {
            case 0: y = 0;
            case 1: y = 1;
            default: y = -1
         }
a.          2
b.          1
c.          0
d.          -1
Key:d
#
3. Assume x is 0. What is the output of the following statement?
if (x > 0)
     System.out.print("x is greater than 0");
else if (x < 0)
     System.out.print("x is less than 0");
else
     System.out.print("x equals 0");
a. x is less than 0
b. x is greater than 0
c. x equals 0
d. None
Key:c
                                                                          2
#
4.     Analyze the following code:
Code 1:
boolean even;
if (number % 2 == 0)
   even = true;
else
   even = false;
Code 2:
#
5. What is the printout of the following switch statement?
char ch = 'a';
     switch (ch) {
       case 'a':
       case 'A':
          System.out.print(ch); break;
       case 'b':
       case 'B':
          System.out.print(ch); break;
       case 'c':
       case 'C':
          System.out.print(ch); break;
       case 'd':
       case 'D':
          System.out.print(ch);
     }
a.    ab
b.    a
                                                               3
c.    aa
d.    abc
e.    abcd
Key:b
#
6.      What is x after evaluating
x = (2 > 3) ? 2 : 3;
a.      5
b.      2
c.      3
d.      4
Key:c
#
7.      Analyze the following code.
     int x = 0;
     if (x > 0);
     {
        System.out.println("x");
     }
#
9.     Which of the following is a constant, according to Java naming
conventions?
a.      read
b.      MAX_VALUE
c.      ReadInt
d.      Test
                                                                               4
Key:b
#
10.   What is y after the following switch statement is executed?
x = 3;
switch (x + 3)    {
    case 6: y     = 0;
    case 7: y     = 1;
    default: y    += 1;
}
a.      1
b.      4
c.      3
d.      2
e.      0
Key:d
#
11. Which of the following code displays the area of a circle if the radius is
positive.