Results 1 to 4 of 4
  1. #1
    staqqa123 is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default ramdom number help needed

    import java.util.Random;

    class RandomNumber{
    public static void main(String [] args){

    Random randomNum = new Random();

    for(int i = 0; i<1; i++)
    {

    System.out.println("Random number is : " + randomNum.nextInt(100));

    }
    }
    }
    but i need it to do this -
    Then add another method that takes a parameter specifying the top number – i.e. if you pass it 50 it returns a random number between 1 and 50. - and i dnt know how to do this

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default Re: ramdom number help needed

    Hi staqqa, welcome to the forums.

    You can declare a method which takes a value as a parameter. This parameter can then be used in the .nextInt method instead of hard coding it as you have done already.

    Regards.

  3. #3
    staqqa123 is offline Member
    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Default Re: ramdom number help needed

    but the thing is i dnt know how to do that? im new to java so all this is new to me n ive just ordered a java for dummies book but it hasnt arrived yet :/

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: ramdom number help needed

    You don't need a book, the basic tutorials cover that: Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    And we won't do it for you.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Replies: 8
    Last Post: 01-21-2012, 02:14 AM
  2. Dice help. posting the number of times a number is rolled.
    By cookiejarvus in forum New To Java
    Replies: 13
    Last Post: 12-05-2011, 12:08 AM
  3. Replies: 26
    Last Post: 11-14-2011, 03:22 PM
  4. Replies: 1
    Last Post: 10-28-2011, 09:18 AM
  5. Printing the Number of Times a Number in a Range Shows up
    By space4rent00 in forum New To Java
    Replies: 1
    Last Post: 02-05-2010, 11:42 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
  •