Java Reference
In-Depth Information
Write a program that prompts the user to enter four points and displays the inter-
secting point. Here are sample runs:
( x 2, y 2)
( x 2, y 2)
( x 3, y 3)
( x 2, y 2)
( x 3, y 3)
( x 3, y 3)
( x 4, y 4)
( x 1, y 1)
( x 1, y 1)
( x 4, y 4)
( x 1, y 1)
( x 4, y 4)
(a)
(b)
(c)
F IGURE 3.8
Two lines intersect in (a and b) and two lines are parallel in (c).
Enter x1, y1, x2, y2, x3, y3, x4, y4: 2 2 5 -1.0 4.0 2.0 -1.0 -2.0
The intersecting point is at (2.88889, 1.1111)
Enter x1, y1, x2, y2, x3, y3, x4, y4: 2 2 7 6.0 4.0 2.0 -1.0 -2.0
The two lines are parallel
3.26
( Use the && , || and ^ operators ) Write a program that prompts the user to enter
an integer and determines whether it is divisible by 5 and 6, whether it is divisible
by 5 or 6, and whether it is divisible by 5 or 6, but not both. Here is a sample run
of this program:
Enter an integer: 10
Is 10 divisible by 5 and 6? false
Is 10 divisible by 5 or 6? true
Is 10 divisible by 5 or 6, but not both? true
**3.27
( Geometry: points in triangle? ) Suppose a right triangle is placed in a plane as
shown below. The right-angle point is placed at (0, 0), and the other two points
are placed at (200, 0), and (0, 100). Write a program that prompts the user to enter
a point with x - and y -coordinates and determines whether the point is inside the
triangle. Here are the sample runs:
(0, 100)
p 2
p 1
(0, 0)
(200, 0)
Enter a point's x- and y-coordinates: 100.5 25.5
The point is in the triangle
 
 
Search WWH ::




Custom Search