Results 1 to 4 of 4

Thread: Die program

  1. #1
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Die program

    Hello again,

    I've writted a die program, and i want the user to type any key in order to continue, how do i achieve this ?

    I have already created a Die class, i just want to implement the main method now.

    PHP Code:
    package test;
    
    /* This program demonstrates the use of a user-defined  *
     * class		                                **/
    
    
    public class RollingDice {
    	
    	// Creates two Die objects and rolls them display the values.
    	
    
    	public static void main (String[] args) {
    		
    		Die die1 = new Die();
    		System.out.println("Roll the die ")
    
    
            }                                                                   
    
    }
    What should i add after System.out.println, So that the user types (any key, or types "Enter" for example, for the die to roll). i dont want the die to roll by itself i Want the user to interact with the program in order for it to roll.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default Re: Die program

    i want the user to type any key
    Look at using the Scanner class with System.in to read the user's input.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: Die program

    yep, i actually added it, and i prompted the user to enter a character in order to continue, but what if i wanted the user to hit the "Enter key" for example, how would i be able to achieve that ???

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default Re: Die program

    what if i wanted the user to hit the "Enter key"
    I don't know how you can control what key a user presses. You can see what has been pressed and respond to that.
    With the Scanner class, nothing is available to the program to read until the user has pressed the Enter key.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: 12-15-2013, 07:40 AM
  2. Replies: 4
    Last Post: 11-21-2012, 02:19 PM
  3. Replies: 2
    Last Post: 04-02-2011, 01:57 PM
  4. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 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
  •