Java Reference
In-Depth Information
while the output of the statement:
if ((8 > 4) | (j++ == 7))
System.out.println("j = " + j);
is:
j = 1
Explain why.
9. What is the output of the following program?
public class Exercise9
{
4
public static void main(String[] args)
{
int myNum = 10;
int yourNum = 30;
if (yourNum % myNum == 3)
{
yourNum = 3;
myNum = 1;
}
else if (yourNum % myNum == 2)
{
yourNum = 2;
myNum = 2;
}
else
{
yourNum = 1;
myNum = 3;
}
System.out.println(myNum + " " + yourNum);
}
}
10. What is the output of the program in Exercise 9, if myNum = 5 and yourNum
= 12 ?
11. What is the output of the program in Exercise 9, if myNum = 30 and
yourNum = 33 ?
Suppose that sale and bonus are double variables. Write an if ... else
statement that assigns a value to bonus as follows: If sale is greater than
$20,000 , the value assigned to bonus is 0.10 ;if sale is greater than
$10,000 and less than or equal to $20,000 , the value assigned to bonus
is 0.05 ; otherwise, the value assigned to bonus is 0 .
12.
Suppose that overSpeed and fine are double variables. Assign the value
to fine as follows: If 0 < overSpeed <= 5 , the value assigned to fine is
$20.00 ;if 5 < overSpeed <= 10, the value assigned to fine is $75.00 ;if 10 <
overSpeed <= 15 , the value assigned to fine is $150.00 ;if overSpeed > 15 ,
the value assigned to fine is $150.00 plus $20.00 per mile over 15 .
13.
Search WWH ::




Custom Search