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

    Default Press enter to continue

    what is the is the java code for this so that when i press enter the program continues in my java program WHERE I INDICATED IT BELOW

    JAVA CODE:

    Java Code:
    package Samurai;
    import java.util.*;
    public class Samurai {
    
    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    
    System.out.println("To Explore your city Press Enter");
    
    
    [B][SIZE=3]// HERE.
    // HOW DO I STOP THE  PROGRAM SO WHEN I PRESS ENTER THATS WHEN THE PROGRAM CONTINUES[/SIZE][/B]
    
    
    cityexplore=(int) (Math.random()*10);
    
    while ((cityexplore%2)==1)
    {
    
    System.out.println(" You Came Across Nothing! Please Keep Exploring");
    
    System.out.println("To Explore your city Press Enter");
    
    cityexplore=(int) (Math.random()*10);
    
    
    }
    
    System.out.println("You came Across A MOBSTER");
    
    }
    
    }
    Last edited by pbrockway2; 01-14-2012 at 11:23 PM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Press enter to continue

    You could read a line of input from the user. Read I/O from the Command Line in Oracle's Tutorial for a discussion of this.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: Press enter to continue

    You might also want to take a look at java.util.Random and its nextInt(int n) method

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    dhanmartin is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Press enter to continue

    i want to get the character without pressing enter key, how should i do that sir?

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Press enter to continue

    Quote Originally Posted by dhanmartin View Post
    i want to get the character without pressing enter key, how should i do that sir?
    Please start your own thread for your own question: this one is about detecting the enter key being pressed which is more or less what your question is not about.

    Also, search because your question is asked a lot.

  6. #6
    dhanmartin is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Press enter to continue

    but you know the answer sir? i am newbie, still dont know how to start a thread.

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Press enter to continue

    Go to the New to Java list of threads. Click the button in the upper left that says "Post new thread".

Similar Threads

  1. Press enter to continue (Jpanel)
    By david522 in forum New To Java
    Replies: 10
    Last Post: 05-22-2011, 03:40 PM
  2. [SOLVED] Press any key to continue??
    By jon80 in forum New To Java
    Replies: 4
    Last Post: 06-15-2009, 11:40 PM
  3. press any key to continue
    By dotnet007 in forum New To Java
    Replies: 3
    Last Post: 05-11-2008, 05:19 AM
  4. Press any key to continue/press enter
    By JT4NK3D in forum New To Java
    Replies: 1
    Last Post: 11-17-2007, 09:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •