Week 2

Extra exercises

If you have already finished all the practice exercises for this week, but would like to get some more hands-on experience with the material, we added some challenging exercises for you to try. Have fun!

Note: we have not yet implemented these exercises in a practice course environment that can be loaded into IntelliJ. So you simply have to make a new project yourself!

  1. A 'palindrome' is a word that reads the same backwards as forwards. Some examples of palindromes are mom, dad, radar, and racecar. Write a program that prompts the user for a word and prints whether the word is a palindrome or not.
  2. Assume you have 50 euros and consider the following game: before the game starts, you determine how many turns you want to play. Each turn, a die is tossed three times. For each time a six is rolled, you win one euro. If no six is rolled in the three tosses, you lose one euro. Write a program that prompts the user for the number of turns he wants to play, plays the game with the number of turns and prints how many euros you have left at the end of the game.
  3. A 'perfect number' is a positive integer that is equal to the sum of its positive divisors (excluding the number itself, but including 1). For example: 6 = 1 + 2 + 3; 28 = 1 + 2 + 4 + 7 + 14; 496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248. Write a program that prompts the user for a number n and then prints all perfect numbers up to the number n.
  4. Write a program that prompts the user for an integer, and then prints how many digits the integer has. If the integer is negative, the minus-sign should not be counted as an extra digit.
You have reached the end of this section!