CISC 190 Chapter 3

Ace your homework & exams now with Quizwiz!

If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal?

(2) str1.equals(str2) (3) (str1.compareTo(str2)==0) answer 2 and 3

If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2?

(3) (str1.compareTo(str2)<0)

To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2?

(str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2)==0)

What will be the value of ans after the following code has been executed? int ans=10; int x=65; int y=55; if(x>=y) ans =x+y;

120

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;

15

Which of the following will format 12.7801 to display as $12.78?

System.out.printf("$%,.2f",12.7801);

The expression tested by an if statement must evaluate to:

true or false

____ works like this: if the expression on the left side of the && operator is false, the expression on the right side will not be checked.

short-circuit evaluation

Which one of the following is the not equal operator?

!=

What would be the value o discountRate after the following statements are executed? double discountRate=0.0; int purchase=100; if(purchase>1000) discountRate=.05; else if(purchase>750) discountRate=.03; else if(purchase>500) discountRate=.01;

0.0

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

0.0

What will be the value of charges after the following code is executed? double charges, rate=7.00; int time=180; charges=time<=119?rate*2: time/60.0*rate;

21.00

What would be the value of bonus after the following statements are executed? int bonus, sales=1250; if(sales>1000) bonus=100; if(sales>750) bonus=50; if(sales>500) bonus=25; else bonus=0;

25

What will be printed when the following code is executed? double x=45678.259; System.out.printf("%,.2f",x);

45678.26

What will be printed when the following code is executed? double x=45678.259; String output=String.format("%,.1f",x); System.out.println(output);

45678.3

What will be the value of pay after the following statements are executed? int hours=45; double pay, payRate=10.00; pay=hours<=40?hours*payRate: 40*payRate+(hours-40)*payRate*1.5;

475.00

What is the value of ans after the following code has been executed? int x=40; int y=40; int ans=0; if(x=y) ans x+10;

No value, this is a syntax error.

if you prematurely terminate an if statement with a semicolon, the compiler will:

Not display an error message Assume you are placing a null statement there

A block of code is enclosed in a set of:

braces {}

Which of the following correctly tests the char variable chr to determine whether it is NOT equal to the character B?

if(chr != 'B')


Related study sets

Chapter 9 Organizational Structure

View Set

Exam Simulator: Florida Life and Health State Exam

View Set

Ch 25 - Fluid, electrolyte, homeostasis

View Set