Java Reference
In-Depth Information
4.22
(Tabular Output)
Write a Java application that uses looping to print the following table of
values:
N 10*N 100*N 1000*N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000
4.23
(Find the Two Largest Numbers)
Using an approach similar to that for Exercise 4.21, find
the
two
largest values of the 10 values entered. [
Note:
You may input each number only once.]
4.24
(Validating User Input)
Modify the program in Fig. 4.12 to validate its inputs. For any in-
put, if the value entered is other than 1 or 2, keep looping until the user enters a correct value.
4.25
What does the following program print?
1
// Exercise 4.25: Mystery2.java
2
public class
Mystery2
3
{
4
public static void
main(String[] args)
5
{
6
int
count =
1
;
7
8
while
(count <=
10
)
9
{
10
System.out.println(count %
2
==
1
?
"****"
:
"++++++++"
);
11
++count;
12
}
13
}
14
}
// end class Mystery2
4.26
What does the following program print?
1
// Exercise 4.26: Mystery3.java
2
public class
Mystery3
3
{
4
public static void
main(String[] args)
5
{
6
int
row =
10
;
7
8
while
(row >=
1
)
9
{
10
int
column =
1
;
11
12
while
(column <=
10
)
13
{
14
System.out.print(row %
2
==
1
?
"<"
:
">")
;
15
++column;
16
}
17
18
--row;
19
System.out.println();
20
}
21
}
22
}
// end class Mystery3