Java Reference
In-Depth Information
21 writeOdds();
22 }
23 }
27. What is the output of the following unknown method?
1 public class Strange {
2 public static final int MAX = 5;
3
4 public static void unknown() {
5 int number = 0;
6
7 for ( int count = MAX; count >= 1; count——) {
8 number += (count * count);
9 }
10
11 System.out.println("The result is: " + number);
12 }
13
14 public static void main(String[] args) {
15 unknown();
16 }
17 }
28. Suppose that you have a variable called line that will take on the values 1, 2, 3, 4, and so on, and a class con-
stant named SIZE that takes one of two values. You are going to formulate expressions in terms of line and SIZE that
will yield different sequences of numbers of characters. Fill in the table below, indicating an expression that will
generate each sequence.
line value
constant SIZE value
Number of characters
Expression
a. 1, 2, 3, 4, 5, 6, ...
1
4, 6, 8, 10, 12, 14, ...
1, 2, 3, 4, 5, 6, ...
2
6, 8, 10, 12, 14, 16, ...
b. 1, 2, 3, 4, 5, 6, ...
3
13, 17, 21, 25, 29, 33, ...
1, 2, 3, 4, 5, 6, ...
5
19, 23, 27, 31, 35, 39, ...
c. 1, 2, 3, 4, 5, 6, ...
4
10, 9, 8, 7, 6, 5, ...
20, 19, 18, 17, 16, 15, ...
1, 2, 3, 4, 5, 6, ...
9
29. Write a table that determines the expressions for the number of each type of character on each of the 6 lines in the
following output.
!!!!!!!!!!!!!!!!!!!!!!
\\!!!!!!!!!!!!!!!!!!//
\\\\!!!!!!!!!!!!!!////
\\\\\\!!!!!!!!!!//////
\\\\\\\\!!!!!!////////
\\\\\\\\\\!!//////////
Search WWH ::




Custom Search