Java Reference
In-Depth Information
If diff is greater than or equal to 50 , the program outputs the message
indicating that the guess is very high (if guess is greater than num )or
very low (if guess is less than num ).
a.
If diff is greater than or equal to 30 and less than 50 , the program
outputs the message indicating that the guess is high (if guess is greater
than num ) or low (if guess is less than num ).
b.
If diff is greater than or equal to 15 and less than 30 , the program
outputs the message indicating that the guess is moderately high (if
guess is greater than num ) or moderately low (if guess is less than num ).
c.
d. If diff is greater than 0 and less than 15 , the program outputs the
message indicating that the guess is somewhat high (if guess is greater
than num ) or somewhat low (if guess is less than num ).
As in Programming Exercise 16, give the user, at most, five tries to
guess the number. (To find the absolute value of num - guess , use the
expression Math.abs(num - guess) .)
18. A high school has 1000 students and 1000 lockers, one locker for each
student. On the first day of school, the principal plays the following game:
She asks the first student to open all the lockers. She then asks the second
student to close all the even-numbered lockers. The third student is asked
to check every third locker. If it is open, the student closes it; if it is closed,
the student opens it. The fourth student is asked to check every fourth
locker. If it is open, the student closes it; if it is closed, the student opens it.
The remaining students continue this game. In general, the nth student
checks every nth locker. If the locker is open, the student closes it; if it is
closed, the student opens it. After all the students have taken their turns,
some of the lockers are open and some are closed. Write a program that
prompts the user to enter the number of lockers in a school. After the game
is over, the program outputs the number of lockers and the locker numbers
of the lockers that are open. Test run your program for the following
inputs: 1000, 5000, and 10,000. Do you see any pattern developing for
the locker numbers that are open in the output?
(Hint: Consider locker number 100. This locker is visited by student
numbers 1, 2, 4, 5, 10, 20, 25, 50, and 100. These are the positive divisors
of 100. Similarly, locker number 30 is visited by student numbers 1, 2, 3, 5,
6, 10, 15, and 30. Note that if the number of positive divisors of a locker
number is odd, then at the end of the game the locker is open. If the
number of positive divisors of a locker number is even, then at the end of
the game the locker is closed.)
5
19. When you borrow money to buy a house, a car, or for some other purpose,
you repay the loan by making periodic payments over a certain time. Of
course the lending company will charge interest on the loan. Every periodic
Search WWH ::




Custom Search