Difference between revisions of "Days in a Month"
Line 15: | Line 15: | ||
|Solution= | |Solution= | ||
− | |SolutionCode=<pre>/* Class DaysInAMonth | + | |SolutionCode=<pre> |
+ | /* Class DaysInAMonth | ||
* Created by Tyler Dielschneider | * Created by Tyler Dielschneider | ||
* Made in COMP3040 | * Made in COMP3040 | ||
Line 28: | Line 29: | ||
{ | { | ||
− | + | public static void main (String args[]) | |
{ | { | ||
// These variables are used for input | // These variables are used for input | ||
Line 35: | Line 36: | ||
// Get input from user | // Get input from user | ||
− | + | input = JOptionPane.showInputDialog(null, "Please enter a month in number format (1-12)."); | |
// Convert string to integer | // Convert string to integer | ||
Line 57: | Line 58: | ||
System.out.println("Invalid Month."); | System.out.println("Invalid Month."); | ||
} | } | ||
− | + | } | |
} | } | ||
Revision as of 14:10, 3 April 2010
Back to the Program-A-Day homepage
ProblemCreate a program that allows the user to enter a month, and then outputs the number of days in that month. For simplicity sake, ask the user for the number of the month rather than the string. Also, assume there are 28 days in February. Use JOptionPane.showInputDialog to capture the input, and System.out.println to generate the output. Make sure the user enters a valid month (1-12). If they enter a number that is not in that range, output "Invalid Month". If the user enters a non-integer, let the program crash.
|
SideSectionTitle
An image or By Students section | |
---|---|---|
Solution | ||
Code |