0% found this document useful (0 votes)
15 views6 pages

Introduction to Java Programming Comprehensive Version 9th Edition Test Bank

Uploaded by

gkqna8thu7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Introduction to Java Programming Comprehensive Version 9th Edition Test Bank

Uploaded by

gkqna8thu7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Test Bank + Answer Key

Test Bank for Introduction to Java Programming Comprehensive


Version 9th Edition by Y. Daniel Liang

View Full Product:


https://selldocx.com/products/test-bank-introduction-to-java-programming-compr

Book Title: Introduction to Java Programming Comprehensive Version

Edition: 9th Edition

Author: Y. Daniel Liang

Click above to view a sample


Name:_______________________ CSCI 1301 Introduction to Programming
Covers Chapters 1-3 Armstrong Atlantic State University
50 mins Instructor: Y. Daniel Liang

Solution:
Part I:
0
8.0
6
false
16
9
43
943 is odd
0

Part II:

1.

import java.util.Scanner;

public class Exercise3_31 {


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();

System.out.print("Enter 0 to convert dollars to RMB and 1 vice versa: ");


int conversionType = input.nextInt();

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;

public class Test {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter an integer: ");
int number = input.nextInt();

if (number % 5 == 0)
System.out.println("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:

boolean even = (number % 2 == 0);

a. Code 2 has syntax errors.


b. Code 1 has syntax errors.
c. Both Code 1 and Code 2 have syntax errors.
d. Both Code 1 and Code 2 are correct, but Code 2 is better.
Key:d

#
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");
}

a. The value of variable x is always printed.


b. The symbol x is always printed twice.
c. The symbol x is always printed.
d. Nothing is printed because x > 0 is false.
Key:c
#
8. To declare a constant MAX_LENGTH inside a method with value 99.98, you
write

a. final double MAX_LENGTH = 99.98;


b. double MAX_LENGTH = 99.98;
c. final MAX_LENGTH = 99.98;
d. final float MAX_LENGTH = 99.98;
Key:a

#
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.

a. if (radius <= 0) System.out.println(radius * radius * 3.14159);


b. if (radius != 0) System.out.println(radius * radius * 3.14159);
c. if (radius >= 0) System.out.println(radius * radius * 3.14159);
d. if (radius > 0) System.out.println(radius * radius * 3.14159);
Key:d

You might also like