|
Spring Semester 2005
|
if Statements.Today in class we will solve these problems:
| 1. |
Write a program that prompts the user for two integers and then
prints
|
|
Here's a sample run with your program:
frilled.cs.indiana.edu%java Two Please enter your first integer number, then press Enter. 3 Please enter your second integer number, then press Enter. 6 3 + 6 = 9 3 - 6 = -3 3 * 6 = 18 avg(3, 6) = 4.5 dist(3, 6) = 3 max(3, 6) = 6 min(3, 6) = 3 frilled.cs.indiana.edu% |
| 2. | Write a program that asks a user to input
orYou will make it You will not make it |
Here's a sample run with your program:
frilled.cs.indiana.edu%java Fourteen Please enter number of gallons then press enter. 10 Please enter fuel efficiency in miles per gallon. 20 Please enter distance in miles you want to cover. 199 You will make it. frilled.cs.indiana.edu%java Fourteen Please enter number of gallons then press enter. 5 Please enter fuel efficiency in miles per gallon. 20 Please enter distance in miles you want to cover. 101 You will not make it. frilled.cs.indiana.edu% |
| 3. |
Write a program that
Here is a sample run. User input is in color. Your program must be able to deal with the case that the first time is later than the second time:Please enter the first time: 0900 Please enter the second time: 1730 8 hours 30 minutes Please enter the first time: 1730 Please enter the second time: 0900 15 hours 30 minutes |
Here's a sample run with your program:
frilled.cs.indiana.edu%java Fifteen Please enter the first time: 0920 Please enter the second time: 1025 1 hours 5 minutes frilled.cs.indiana.edu%java Fifteen Please enter the first time: 1025 Please enter the second time: 0920 22 hours 55 minutes frilled.cs.indiana.edu% |
| 4. |
Write a program that transforms numbers
into the corresponding month names
|
Here's a sample run with your program:
frilled.cs.indiana.edu%java Eighteen Please enter a month number from 1 to 12. 2 February frilled.cs.indiana.edu%java Eighteen Please enter a month number from 1 to 12. 12 December frilled.cs.indiana.edu%java Eighteen Please enter a month number from 1 to 12. 1 January frilled.cs.indiana.edu%java Eighteen Please enter a month number from 1 to 12. 14 Exception in thread "main" [...] frilled.cs.indiana.edu% |
The code will be printed after the lecture.
For each program we will be using if statements to determine the course of action.
In all cases we will be thinking how we could have solved this problem without
the use of if.
Thu Jan 27 10:41:58 EST 2005