DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    2

    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.");
    }


    }

    }

  2. #2
    Join Date
    Aug 2005
    Posts
    43

  3. #3
    Join Date
    Oct 2005
    Posts
    2
    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

  1. Replies: 3
    Last Post: 07-24-2005, 01:37 PM
  2. Pause and resume a download
    By troublesome in forum Java
    Replies: 0
    Last Post: 06-20-2005, 06:49 PM
  3. Form inputs and images.....
    By Joe in forum Web
    Replies: 1
    Last Post: 02-01-2001, 09:13 AM
  4. pause for keypress
    By Ben in forum Java
    Replies: 0
    Last Post: 11-21-2000, 01:50 AM
  5. How do I pause a printer?
    By Darco in forum VB Classic
    Replies: 0
    Last Post: 08-12-2000, 03:53 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links