Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Delay.

  1. #1
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Delay.

    Is it possible to create a delay in java? I've been wondering this for a while. Then, could you use a variable in the delay thats a double?
    Ex.

    import java.util.Scanner;
    // Program starting (class etc, void main)
    Scanner scan = new Scanner(System.in);
    double delaysec;
    System.out.println("How many seconds do you want to wait for each prompt?");
    delaysec = scan.next.Double(); // Get the double
    // delay command for delaysec amount
    for(int x = 0; x<5;x++) // Do it 5 times
    {
    System.out.println("This has waited : " + delaysec + "seconds.");
    //Delay command again
    }
    // End program


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Delay.

    long sleepInMilliseconds = 1000;//1 second
    try{
        Thread.sleep(sleepInMilliseconds );
    }catch(InterruptedException e){
     
    }

  3. The Following User Says Thank You to copeg For This Useful Post:

    Tjstretch (October 21st, 2010)

Similar Threads

  1. video game problem - delay in response to arrow key presses
    By gib65 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 17th, 2010, 07:39 PM
  2. Delay/Wait/Pause in Java + AirBrushing
    By obliza in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 27th, 2009, 10:27 AM