Archive for December, 2007

Chapter 6, 6.5

1. Writhe output of the following code segments:
a.1 2 3 1 2 3 1 2 3
b. 1 2 3
1 2 3
1 2 3

2. Write code segments that solve the following problems:
a.Output the numbers 1 to 25 in consecutive order, using five rows of five numbers each.
-for(i=0; i<5; i++)
for(j=1; j<=5; j++)
System.out.print((i*5+j) + “”)
System.out.println(“”)

b.Output five rows of five numbers. Each number is the sum of its row position and column position. The position of the first number is (1,1):

Chapter 6, 6.4

1. Write the outputs of the following code segment:
-The logic error is the order. Ther 50000 should be placed first and then 20000, and 10000. For example, for a guy with 25000 income, his tax income will be 0.18. The code should contain number in a descending order.

2. Write a correct code segment for the problem in Question 1.
-if (income> 50000)
rate = 0.40;
else if (income > 20000)
rate = 0.18;
else if (income > 10000)
rate = 0.10;
else
rate = 0.0;

Chapter 6, 6.3

1. Construct a truth table that shows all the possible paths through the following nested if statement:
-Before noon Monday Action Taken
true true take the computer science quiz
true false go to gym class
false true throw a Frisbee in the quad
false false throw a Frisbee in the quad

2. What is the difference between a nested if statement and a multiway if statement?
-The nested if statement provides conditions within conditions and a multiway if statement provides alternative conditions in the same level.