Results 1 to 6 of 6
  1. #1
    dharav is offline Member
    Join Date
    Dec 2011
    Posts
    28
    Rep Power
    0

    Question Time Intervals In Java Outprint

    Hey Forum Users,


    I have a game to make in my class and this is the code

    Java Code:

    package Samurai;
    import java.util.*;
    public class Samurai {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub


    String nameofwarrior;
    Scanner keyboard = new Scanner (System.in);
    System.out.println("Hey The Ol'e Wise Man Wishes to Know your NAME");
    nameofwarrior=keyboard.nextLine();
    System.out.println("*.**.* YOU ARE THE CHOOSEN ONE "+nameofwarrior+" *.**.* \n DESTINY AWAITS YOU ON YOUR JOURNEY \n CHOOSE YOUR BEGINING HOMETOWN");
    }
    }





    So the question is that how can i have a time interval of outprint between 2 System.out.println("thecomment");

    so that 1 print after 2 seconds after printing the other
    Last edited by dharav; 01-10-2012 at 02:27 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Time Intervals In Java Outprint

    java.util.Timer / TimerTask

    db

    edit Or if it's really as simple as the code you posted, Thread#sleep(...)
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: Time Intervals In Java Outprint

    Java Code:
    System.out.println ("...") ;// first output
    try
          {
            Thread.sleep(1000); // a simple timer of 1 second (1000 milliseconds)
          }
          catch (InterruptedException e)
          {}
    System.out.println ("...") ;// second output

  4. #4
    dharav is offline Member
    Join Date
    Dec 2011
    Posts
    28
    Rep Power
    0

    Default Re: Time Intervals In Java Outprint

    Thank you Cuppa Coffee it worked like a charm and this is my final code

    Java Code:



    package Samurai;
    import java.util.*;
    public class Samurai {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    String nameofwarrior;

    Scanner keyboard = new Scanner (System.in);
    System.out.println("Hey The Ol'e Wise Man Wishes to Know your NAME");
    nameofwarrior=keyboard.nextLine();
    System.out.println("*.**.* YOU ARE THE CHOOSEN ONE "+nameofwarrior+" *.**.* \n DESTINY AWAITS YOU ON YOUR JOURNEY \n CHOOSE YOUR BEGINING HOMETOWN");
    try
    {
    Thread.sleep(1000); // a simple timer of 1 second (1000 milliseconds)
    }
    catch (InterruptedException e)
    {}
    System.out.println("You are chooosen TO be the one");

    }
    }



    Thank you Again and the Thread should be closed.

  5. #5
    dharav is offline Member
    Join Date
    Dec 2011
    Posts
    28
    Rep Power
    0

    Default Re: Time Intervals In Java Outprint

    How do you close the post

  6. #6
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: Time Intervals In Java Outprint

    Just let the mods take care of it

Similar Threads

  1. Intervals of Days and Weeks
    By jazob in forum New To Java
    Replies: 0
    Last Post: 12-14-2011, 10:55 PM
  2. Replies: 3
    Last Post: 12-07-2011, 07:00 AM
  3. Replies: 3
    Last Post: 08-23-2011, 12:46 PM
  4. Setting unveven intervals in chart range axis
    By deeps in forum Advanced Java
    Replies: 0
    Last Post: 03-30-2010, 06:11 AM
  5. how to change password in regular intervals
    By mohan404 in forum Advanced Java
    Replies: 4
    Last Post: 04-08-2008, 11:46 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
  •