-
Pause between inputs
I have a program I am writing for a class. I need it to accept three inputs, and it does that now. But it asks for all three at once and it takes all three at once. I need it to request the first input, receive that, request the second, receive that, and then request the third, then give the output. I hate to ask such a general question like "How do I do this." Can someone point me in the right direction without saying "Do it like this?" Thanks, Dennis
CODE FOLLOWS:
import java.util.Scanner;
public class Calendar
{
// obtain three integers
public static void main(String args[])
{
// create Scanner for input from command window
Scanner input = new Scanner( System.in );
// prompt for and input three integers
System.out.print( "Enter a Year, 1800 or later: \n" );
System.out.print( "Enter the number of the Month: \n" );
System.out.print( "Enter the number of the Day: \n" );
int num1 = input.nextInt(); // read first int
int num2 = input.nextInt(); // read second int
int num3 = input.nextInt(); // read third int
if ( num1 <= 1799 )
{
System.out.println("Please choose a valid year.");
} else {
System.out.println("You chose: ");
System.out.println(num1 + ".");
}
if ( num2 < 13 )
{
System.out.println("You chose: ");
System.out.println(num2 + ".");
} else {
System.out.println("Please choose a valid number for month.");
}
if ( num3 < 32 )
{
System.out.println("You chose: ");
System.out.println(num3 + ".");
} else {
System.out.println("Please choose a valid number for day.");
}
}
}
-
-
Actually, I solved it by doing the following
// prompt for and input integers for year and month
System.out.print( "Enter a Year, 1800 or later: \n" );
int num1 = input.nextInt(); // read first int
System.out.print( "Enter the number of the Month: \n" );
int num2 = input.nextInt(); // read second int
System.out.print( "Enter the number of the Day: \n" );
int num3 = input.nextInt(); // read third int
This seems to be much easier and much less involved.
Similar Threads
-
By gnosnahz in forum Java
Replies: 3
Last Post: 07-24-2005, 01:37 PM
-
By troublesome in forum Java
Replies: 0
Last Post: 06-20-2005, 06:49 PM
-
Replies: 1
Last Post: 02-01-2001, 09:13 AM
-
Replies: 0
Last Post: 11-21-2000, 01:50 AM
-
By Darco in forum VB Classic
Replies: 0
Last Post: 08-12-2000, 03:53 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks