Java Reference
In-Depth Information
For example, the union of two array lists {2, 3, 1, 5} and {3, 4, 6} is
{2, 3, 1, 5, 3, 4, 6}. Write a test program that prompts the user to enter two lists,
each with five integers, and displays their union. The numbers are separated by
exactly one space in the output. Here is a sample run:
Enter five integers for list1: 3 5 45 4 3
Enter five integers for list2: 33 51 5 4 13
The combined list is 3 5 45 4 3 33 51 5 4 13
*11.15
( Area of a convex polygon ) A polygon is convex if it contains any line segments
that connects two points of the polygon. Write a program that prompts the user to
enter the number of points in a convex polygon, then enter the points clockwise,
and display the area of the polygon. Here is a sample run of the program:
Enter the number of the points: 7
Enter the coordinates of the points:
-12 0 -8.5 10 0 11.4 5.5 7.8 6 -5.5 0 -7 -3.5 -3.5
The total area is 250.075
**11.16
( Addition quiz ) Rewrite ListingĀ  5.1 RepeatAdditionQuiz.java to alert the user
if an answer is entered again. Hint: use an array list to store answers. Here is a
sample run:
What is 5 + 9? 12
Wrong answer. Try again. What is 5 + 9? 34
Wrong answer. Try again. What is 5 + 9? 12
You already entered 12
Wrong answer. Try again. What is 5 + 9? 14
You got it!
**11.17
( Algebra: perfect square ) Write a program that prompts the user to enter an inte-
ger m and find the smallest integer n such that m * n is a perfect square. ( Hint:
Store all smallest factors of m into an array list. n is the product of the factors that
appear an odd number of times in the array list. For example, consider m
90,
store the factors 2, 3, 3, 5 in an array list. 2 and 5 appear an odd number of times
in the array list. So, n is 10.) Here are sample runs:
=
Enter an integer m: 1500
The smallest number n for m * n to be a perfect square is 15
m * n is 22500
Enter an integer m: 63
The smalle
st number n for m * n to be a perfect square is 7
m * n is 441
 
 
Search WWH ::




Custom Search