Friday, May 6, 2011

chapter 3

What would be the value of 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;

===Cannot tell from code

Which of the following will format 12.78 to display as 12.8%?
==##0.0%

What does the following code display?

int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);

===9 12

Which of the following correctly tests the char variable chr to determine whether it is not equal to the character B?
==if (chr != 'B')

This is a boolean variable that signals when some condition exists in the program
==Flag

The expression in an if statement must evaluate to
==true or false

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

Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster if the subexpression most likely false expression is on the left.
==true

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

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

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?
==((x > 500 && x < 650) || (y != 1000))


What would be the value of discountRate after the following statements are executed?

double discountRate = 0.0;
int purchase = 1250;
if (purchase > 1000)
discountRate = .05;
if (purchase > 750)
discountRate = .03;
if (purchase > 500)
discountRate = .01;
else
discountRate = 0

===0.01

A flag may have the values
==true or false

What does the following code display?

double x = 12.3798146;
System.out.printf("%.2f\n", x);
==12.38

What is the value of ans after the following code has been executed?

int x = 35;
int y = 20, ans = 80;
if (x < y);
ans += y;
==100


Because the || operator performs short-circuit evaluation, your boolean statement will generally run faster if the subexpression that is most likely to be true is on the left.
==true

What would be the value of bonus after the following statements are executed?

int bonus, sales = 85000;
char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;

==1000

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



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

In a switch statement, if two different values for theCaseExpression would result in the same code being executed, you must have two copies of the code, one after eachCaseExpression.
==false

What will be the value of ans after the following code has been executed?

int x = 65;
int y = 55;
if (x >= y)
int ans = x + y;
==120

When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
==false


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.

The ________ statement is used to make simple decisions in Java.
==if

What will be printed when the following code is executed?

double x = 45678.259;
DecimalFormat formatter =
new DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));

====45,678.26

No comments:

Post a Comment

Post a Comment