THIS PAGE CONTAINS programming exercises based on material from Chapter 3 of this on-line Java textbook. Your number of eggs is 9 gross, 3 dozen, and 10 For example, if the user says that she has 1342 eggs, then your program would respond with Extend your program so that it will tell the user how many gross, how many dozen, and how many left over eggs she has. (This is essentially the definition of the / and % operators for integers.) Write a program that asks the user how many eggs she has and then tells the user how many dozen eggs she has and how many extra eggs are left over.Ī gross of eggs is equal to 144 eggs. Then the program should tell the user how much money he has, expressed in dollars.Įxercise 2.5: If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left over. The program should ask how many quarters the user has, then how many dimes, then how many nickels, then how many pennies. For example, if the user's name is Fred, then the program should respond "Hello, FRED, nice to meet you!".Įxercise 2.4: Write a program that helps the user count his change. Before outputting the user's name, convert it to upper case letters. (Note: The word "dice" is a plural, as in "two dice." The singular is "die.")Įxercise 2.3: Write a program that asks the user's name, and then greets the user by name. Your program should report the number showing on each die as well as the total roll. Do this twice and add the results together to get the total roll. You can assign this value to a variable to represent one of the dice that are being rolled. As pointed out in Section 5, The expressionĭoes the computation you need to select a random integer between 1 and 6. The number you pick represents the number on the die after it is rolled. You can simulate rolling one die by choosing one of the integers 1, 2, 3, 4, 5, or 6 at random. For example, if your initials were "DJE", then the output would look something like:Įxercise 2.2: Write a program that simulates rolling a pair of dice. Each big letter should be made up of a bunch of *'s. Each exercise has a link to a discussion of one possible solution of that exercise.Įxercise 2.1: Write a program that will print your initials to standard output in letters that are nine lines tall. ![]() THIS PAGE CONTAINS programming exercises based on material from Chapter 2 of this on-line Java textbook.
0 Comments
Leave a Reply. |