Can someone tell me how to do this


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Can someone tell me how to do this

  1. #1
    Edward Guest

    Can someone tell me how to do this


    how do i generate a random number
    and then use this generated number to compare it with a number a user enters.

    How can i use [y]es and [n]o . For example a user enter y and then in the
    program I want to insert an if and else statement
    how can i use if and else to guide the program to do certain things. Please
    email me.

  2. #2
    Paul Clapham Guest

    Re: Can someone tell me how to do this

    If you don't know how to use "if" and "else" statements you should have
    posted this in the java.getting.started newsgroup, or better still, find a
    book that teaches you Java. There are lots. However...

    if (boolean) {list of statements;}
    else {list of statements;}

    To generate a random number you use the static method "random" that's in the
    class "Math" as follows:

    double x = Math.random();

    If you download the Java documentation from Sun's site it's not hard to find
    this out... look in the index under "random" and there it is.

    Edward <xocafox@aol.com> wrote in message news:38f7dfc1$1@news.devx.com...
    >
    > how do i generate a random number
    > and then use this generated number to compare it with a number a user

    enters.
    >
    > How can i use [y]es and [n]o . For example a user enter y and then in the
    > program I want to insert an if and else statement
    > how can i use if and else to guide the program to do certain things.

    Please
    > email me.




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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center