Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
- Consider the following code snippet.
Which operators does the code contain?arrayOfInts[j] > arrayOfInts[j+1]- Consider the following code snippet.
int i = 10; int n = i++%5;
- What are the values of
i
andn
after the code is executed?- What are the final values of
i
andn
if instead of using the postfix increment operator (i++
), you use the prefix version (++i)
)?- What is the value of
i
after the following code snippet executes?int i = 8; i >>=2;- What is the value of
i
after the following code snippet executes?int i = 17; i >>=1;
Check your answers.
- Write a program that tests whether a floating-point number is zero. (Hint: Generally, you shouldn't use the equality operator,
==
, with floating-point numbers since floating-point numbers by nature are difficult to match exactly. Instead, test whether the number is close to zero.)- Write a program that calculates the number of U.S. dollars equivalent to a given number of euros. Assume an exchange rate of 0.781162 euros per dollar. If you want to control the format of the numbers your program displays, you can use the
DecimalFormat
class, which is discussed in the Formatting Numbers with Custom Formats section.- Write a program that uses the bits in a single integer to represent the
true
/false
data shown in the following figure.Include in the program a variable named Shows the
true
/false
data to be represented by the bits in an integer.status
and have the program print the meaning ofstatus
. For example, ifstatus
is 1 (only bit 0 is set), the program should print something like this.Ready to receive requests
- Show your code.
- What is the output when
status
is 8?- What is the output when
status
is 7?
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.