loops :: problem set 2

Make sure to check for the validity of the data inputted by the user

  1. Write a program that separately adds all numbers divisible by 3 and 5, all numbers divisble only by 3 and all numbers divisible only by 5, between the integers 0 to 50. (hint: you may need mod for this one)
  2. Write a program that simulates the rolling of two dice. First, roll the first die once. Then, roll the second die and count how many rolls it took the second die to get the same value as the first die. To randomize the values use:
    int die = (int)(Math.random() * 6) + 1;
  3. Modify the die program so it rolls both dice 500 times. Count the number of times each value occurred. Your output should look like this:

    2's = n times
    3's = n times
    .
    .
    12's = n times

  4. Write a program that could be used to play a simple game. The program should first ask a user to supply a positive integer less than 1000 (or this value can be generated by the program). Once the value has been provided, the program should then ask a second user to guess the number that was given by the first user. After each incorrect guess, the program should output to this user whether the guess was high or too low and ask for another guess. This should continue until the second user guesses the correct number. The program should then print the number of guesses that the second user needed to guess the correct number.
  5. George has 231 jelly beans in a bag. Every third day he eats 6 jelly beans. Every 5th day, he purchases 8 more. How many days elapse before George runs out of jelly beans?
For answers click here