Java Reference
In-Depth Information
2
Note that you can use Math.pow(x, 0.5) to compute
x .
Here are some sam-
ple runs.
1.0 3 1
Enter a, b, c:
The roots are -0.381966 and -2.61803
1 2.0 1
Enter a, b, c:
The root is -1
1 2 3
Enter a, b, c:
The equation has no real roots
3.2
( Game: add three numbers ) The program in Listing 3.1 generates two integers and
prompts the user to enter the sum of these two integers. Revise the program to
generate three single-digit integers and prompt the user to enter the sum of these
three integers.
Sections 3.3-3.8
*3.3
( Algebra: solve
2
*
2
linear equations ) You can use Cramer's rule to solve the
following
2
*
2
system of linear equation:
ed
-
bf
af
-
ec
ax
+
by
=
e
f
x
=
bc
y
=
cx
+
dy
=
ad
-
ad
-
bc
Write a program that prompts the user to enter a , b , c , d , e , and f and displays the
result. If
ad
-
bc
is 0 , report that “The equation has no solution”.
Enter a, b, c, d, e, f:
x is -2.0 and y is 3.0
9.0 4.0 3.0 -5.0 -6.0 -21.0
Enter a, b, c, d, e, f:
The equation has no solution
1.0 2.0 2.0 4.0 4.0 5.0
**3.4
( Game: learn addition ) Write a program that generates two integers under 100
and prompts the user to enter the sum of these two integers. The program then
reports true if the answer is correct, false otherwise. The program is similar to
Listing 3.1.
*3.5
( Find future dates ) Write a program that prompts the user to enter an integer for
today's day of the week (Sunday is 0, Monday is 1, . . ., and Saturday is 6). Also
prompt the user to enter the number of days after today for a future day and dis-
play the future day of the week. Here is a sample run:
Enter today's day:
Enter the number of days elapsed since today:
Today is Monday and the future day is Thursday
1
3
 
Search WWH ::




Custom Search