Java Reference
In-Depth Information
*3.8
(
Sort three integers
) Write a program that prompts the user to enter three integers
and display the integers in non-decreasing order.
VideoNote
**3.9
(
Business: check ISBN-10
) An
ISBN-10
(International Standard Book Number)
consists of 10 digits:
d
1
d
2
d
3
d
4
d
5
d
6
d
7
d
8
d
9
d
10
. The last digit,
d
10
, is a checksum,
which is calculated from the other nine digits using the following formula:
Sort three integers
(
d
1
*
1
+
d
2
*
2
+
d
3
*
3
+
d
4
*
4
+
d
5
*
5
+
d
6
*
6
+
d
7
*
7
+
d
8
*
8
+
d
9
*
9) % 11
If the checksum is
10
, the last digit is denoted as X according to the ISBN-10
convention. Write a program that prompts the user to enter the first 9 digits and
displays the 10-digit ISBN (including leading zeros). Your program should read
the input as an integer. Here are sample runs:
Enter the first 9 digits of an ISBN as integer: 013601267
The ISBN-10 number is 0136012671
Enter the first 9 digits of an ISBN as integer: 013031997
The ISBN-10 number is 013031997X
3.10
(
Game: addition quiz
) Listing 3.3, SubtractionQuiz.java, randomly generates a
subtraction question. Revise the program to randomly generate an addition ques-
tion with two integers less than 100.
Sections 3.8-3.16
*3.11
(
Find the number of days in a month
) Write a program that prompts the user
to enter the month and year and displays the number of days in the month. For
example, if the user entered month
2
and year
2012
, the program should display
that February 2012 had 29 days. If the user entered month
3
and year
2015
, the
program should display that March 2015 had 31 days.
3.12
(
Palindrome number
) Write a program that prompts the user to enter a three-digit
integer and determines whether it is a palindrome number. A number is palin-
drome if it reads the same from right to left and from left to right. Here is a sample
run of this program:
Enter a three-digit integer: 121
121 is a palindrome
Enter a three-digit integer: 123
123 is not a palindrome
*3.13
(
Financial application: compute taxes
) Listing 3.5, ComputeTax.java, gives the
source code to compute taxes for single filers. Complete Listing 3.5 to compute
the taxes for all filing statuses.
3.14
(
Game: heads or tails
) Write a program that lets the user guess whether the flip of
a coin results in heads or tails. The program randomly generates an integer
0
or
1
,
which represents head or tail. The program prompts the user to enter a guess and
reports whether the guess is correct or incorrect.
Search WWH ::
Custom Search