Chapter 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%? "##0.0%" "###.##%" "000.0%" "#0.00%"

"##0.0%"

What would 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; 0.0 0.05 0.03 0.01

0.0

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

0.0

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

True

The DecimalFormat class is part of the Java API, but it is not automatically available to your programs. True False

True

What would 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; 0.0 0.04 0.05 0.03

0.04

What will be the value of bonus after the following code is executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250; 750 1250 500 1000

1000

What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x>y) x = x - y; 60 75 15 135

15

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

20

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.prinln(pay); 300.0 600.0 400.0 The code contains an error and will not compile.

300.0

What will be displayed when the following code is executed? int y= 10; if (y == 10) { int x = 30; x += y; System.out.println(x); } 40 30 20 The code contains an error and will not compile.

40

What will be displayed when the following code is executed? double x=45678.259; DecimalFormat formatter = new DecimalFormat("#,##0.0"); JOptionPane.showMessageDialog(null, formatter.format(x)); 45,678.26 45,678.3 45,678.259 45678.259

45,678.3

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

a set of parentheses

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;} ans = 60, x = 0, y = 50 ans = 45, x = 50, y = 0 ans = 45, x = 50, y = 50 ans = 60, x = 50, y =100

ans=60,x=0,y=50

A block of code is enclosed in a set of parentheses. brackets. braces. double quotes.

braces

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

chrA != 'A'

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

error

When testing for character values, the switch statement does not test for the case of the character. True False

false

When two strings are compared using the String class's compareTo method, the comparison is case-insensitive. True False

false

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

if

Which of the following statements determines whether temp is within the range of 0 through 100?

if (temp >=1 && temp <= 100)

________ operators are used to determine whether a specific relationship exists between two values. Assignment Arithmetic Logical Relational

relational

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

str1.equalsignorCase(str2)

In an if-else statement, if the boolean expression is false

the statement of block following the else is executed.

A local variable's scope always ends at the closing brace of the block of code in which it is declared. True False

true

An important style rule you should adopt for writing if statements is to write the conditionally executed statement on the line after the if statement. True False

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 true false

true

Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets. True False

true

A flag may have the values defined or undefined. of any range of numbers. true or false. of any Unicode character.

true or false

The boolean expression in an if statement must evaluate to degrees or radians. true or false. positive or negative. left or right.

true or false

A flag may have the values defined or undefined. of any range of numbers. true or false. of any Unicode character.

ture or false

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

x<=y

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

0.0 (because there are no "breaks")


Kaugnay na mga set ng pag-aaral

NCLEX Women's Health and Maternity/Newborn Drugs

View Set

A&P2 Final Ultimate Prep AND Past Exams- AP2

View Set

Semester 1 Final (Not including Math for Science quiz)

View Set

Lab Quiz 2 for MCRO 251 UNC (Labs 6-11)

View Set

Chapter 5: Beyond the World of Words

View Set