Computer Programming Test #3

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

When determining whether a number is inside a range, it's best to use this operator. a) && b) ! c) || d) ?:

a) &&

A random number, created as an object of the Random class, is always an integer. a) true b) false

b) false

In an if-else statement, if the boolean expression is false a) no statements or blocks are executed b) the statement or block following the else is executed c) the first statement or block is executed d) all the statements or blocks are executed

b) the statement or block following the else is executed

A flag may have the values a) defined or undefined b) true or false c) any range of integers d) of any unicode character

b) true or false

What will be displayed after the following statements are executed? int x = 65; int y = 55; if (x >= y) { int ans = x + y; } System.out.println(ans); a) 10 b) 100 c) 120 d) The code contains an error and will not compile.

c) 120

What will be the value of discountRate after the following statements are executed? double discountRate=0.0; int purchase=100; if (purchase>1000) discountRate=0.05; else if (purchase>750) discountRate=0.03; else if (purchase>500) discountRate=0.01; a) 0.0 b) 0.03 c) 0.01 d) 0.05

a) 0.0

What will be the value of x after the following statements are executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; } a) 20 b) 25 c) 5 d) 30

a) 20

Which of the following statements will create an object from the Random class? a) Random myNumber = new Random(); b) myNumber = new Random(); c) Random = new randomNumbers(); d) randomNumbers() = new Random();

a) Random myNumber = new Random();

Which of the following expressions determines whether the char variable, chrA, is not equal to the letter 'A'? a) chrA != 'A' b) chrA == 'A' c) chrA.notEquals(A) d) chrA || 'A'

a) chrA != 'A'

A ___________ is a Boolean variable that signals when some conditions exists in the progress. a) case b) flag c) block d) sentinel

a) flag

Which of the following expressions will generate a random number in the range of 1 through 10? a) myNumber = randomNumbers.nextInt(10) + 1; b) myNumber = randomNumbers.nextInt(11) - 1; c) myNumber = randomNumbers.nextInt(1) + 10; d) myNumber = randomNumbers.nextInt(10);

a) myNumber = randomNumbers.nextInt(10) + 1;

Select all that apply. Which method of the Random class will return a random number within the range of 0.0 and 1.0? a) nextDouble() b) nextlong() c) nextFloat() d) nextInt(int n)

a) nextDouble() c) nextFloat()

>,<, and == are ____________. a) relational operators b) logical operators c) conditional operators d) ternary operators

a) relational operators

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2? a) str1.equalsIgnoreCase(str2) b) str.equalsInsensitive(str2) c) str1 != str2 d) str1 || str2

a) str1.equalsIgnoreCase(str2)

All it takes for an OR expression to be true is for one of the subexpressions to be true. a) true b) false

a) true

An important style rule that should be used when writing if statements is to write the conditionally executed statement on the line after the if statement. a) true b) false

a) true

If the expression on the left side of the && operator is false, the expression on the right side will not be checked. a) true b) false

a) true

The if-else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false. a) true b) false

a) true

Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL the world's alphabets. a) true b) false

a) true

How does the character 'A' compare to the character 'B'? a) 'A' is greater than 'B' b) 'A' is less than 'B' c) 'A' is equal to 'B' d) You cannot compare characters

b) 'A' is less than 'B'

What will be the value of discountRate after the following statements are executed? double discountRate; char custType='B'; switch (custType) { case 'A': discountRate = 0.08; break; case 'B': discountRate = 0.06; case 'C': discountRate = 0.04; default: discountRate = 0.0 } a) 0.06 b) 0.0 c) 0.04 d) 0.08

b) 0.0

What will be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if (purchase > 1000) if (cust == 'Y') discountRate = 0.05; else discountRate = 0.04; else if (purchase > 750) if (cust== 'Y') discountRate = 0.04; else discountRate = 0.03; else discountRate = 0.0; a) 0.0 b) 0.04 c) 0.05 d) 0.03

b) 0.04

What will be the value of bonus after the following statements are executed? int bonus, sales=10000; if (sales<5000) bonus = 200; else if (sales <7500) bonus = 500; else if (sales <10000) bonus = 750 else if (sales < 20000) bonus = 1000; else bonus = 1250; a) 750 b) 1000 c) 500 d) 1250

b) 1000

What will be the value of x after the following statements are executed? int x=75; int y=60; if (x>y) x=x-y a) 135 b) 15 c) 60 d) 75

b) 15

What will be displayed after the following statements are executed? int hours = 30; double pay, payRate = 10.00; pay=hours<=40 ? hours * payRate : hours *payRate*2.0; System.out.println(pay); a) 600.0 b) 300.0 c) 400.0 d) The code contains an error and will not compile.

b) 300.0

What will be the values of ans, x, and y after the following statements are executed?int ans=35, x=50, y=50; if (x>=y) {ans=x+10; x -= y;} else {ans = y+10; y += x;} a) ans = 45, x = 50, and y = 50 b) ans = 60, x = 0, and y = 50 c) ans = 60, x = 50, and y = 100 d) ans = 45, x = 50, and y = 0

b) ans = 60, x = 0, and y = 50

A block of code is enclosed in a set of a) parentheses, () b) braces, {} c) brackets, [] d) double quotes, ""

b) braces,{}

All it takes for an AND expression to be true is for one of the subexpression to be true. a) true b) false

b) false

In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression. a) true b) false

b) false

The = operator and the == operator perform the same operation. a) true b) false

b) false

When testing for character values, the switch statement does not test for the case of the character. a) true b) false

b) false

When two strings are compared using the String class's compareTo method, the comparison is case-insensitive. a) true b) false

b) false

The ________ statement is used to create a decision structure which allows a program to have more than one path of execution. a) flag b) if c) null d) block

b) if

What will be displayed after the following statements are executed? int y = 10; if (y == 10) { int x = 30; x += y; System.out.println(x); } a) 20 b) 30 c) 40 d) The code contains an error and will not compile.

c) 40

When a character is stored in memory, it is actually the ________ that is stored. a) floating-point value b) letter, symbol, or number c) Unicode number d) ASCII code

c) Unicode number

Enclosing a group of statements inside a set of braces creates a) a relational operator b) a conditional statement c) a block of statements d) an expression.

c) a block of statements

The conditional operator takes this many operands. a) one b) two c) three d) four

c) three

The boolean expression in an if statement must evaluate to a) degrees or radians b) postive or negative c) true or false d) left or right

c) true or false

Which of the following expressions will determine whether x is less than or equal to y? a) x => y b) x >= y c) x <= y d) x =< y

c) x <= y

______ operators are used to determine whether a specific relationship exists between two values. a) assignment b) arithmetic c) logical d) relational

d) Relational

What will be the value of ans after the following statements are executed? int x=40; int y=40; if (x = y) ans = x+10; a) 30 b) 50 c) 80 d) The code contains an error and will not compile.

d) The code contains an error and will not compile.

Java requires that the boolean expression being tested by an if statement be enclosed in a) a set of brackets b) a set of braces c) a set of double quotes d) a set of parentheses.

d) a set of parentheses

Which of the following statements determines whether the variable temp is within the range of 0 through 100 (inclusive)? a) if (temp > 0 || temp < 100) b) if (temp >= 0 || temp <= 100) c) if (temp > 0 && temp < 100) d) if (temp >= 0 && temp <= 100)

d) if (temp >= 0 && temp <= 100)

If str1 and str2 are both String objects, which of the following will correctly test to determine whether or not they are equal? a) str1 = str2 b) str1 && str2 c) str1.equals(str2) d) str1 += str2

str1.equals(str2)


Set pelajaran terkait

Commercial Underwriting Principles Test 6

View Set

Chapter 3: The Balance Sheet and Financial Disclosures

View Set

Biology Review (Pearson questions)

View Set

Chapter 9: Making Capital Investment Decisions

View Set

Content Quiz 2: Forecasting (Module 2)

View Set

if you could be beautiful and not so smart or brilliant and not so beautiful what would it be a why?

View Set

Immunology Unit 3 - Chapter 10 T-Cell Activation, Helper Subset Differentiation, and Memory

View Set