Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Printing random values from array list.

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Printing random values from array list.

    Hello guys,
    I am having a hard time trying to figure out how to print random numbers from a an array list. I tried google but nothing worked. I have to pick certain values from two lists and print them on the screen. I have included comments in the code to facilitate the explanation. Thank very much in advance.


    This is my code:

     
     
     
    import java.util.Random;
    public class Parachute {
     
     
    	public static void main(String[] args) {
    		Random randomNumbers=new Random();
    int number;		
     
     
     
    int array []={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
    char A[] = {'a', 'b', 'c','d','e','f','g','h', 'i','j','k','l','m','n','o','p','q'}; 
     
    number = 5 + randomNumbers.nextInt(2);
     
    if ( number==5 )
     
    {
    	number=1+randomNumbers.nextInt(3);
     
    	if (number==1)////pick and print 3 random letters from char and pick and print one random number
    	{System.out.println("3 random letters and one random number");}
     
    	if (number==2)///pick and print 2 random numbers and 1 random letter from char
    	{System.out.println("2 random numbers and one randon letter");}
     
    	if (number==3)///pick 5 random letters
    	{System.out.println("5 random letters " );}
     
    }
     
    if (number==6)// pick and print 5 random letters
    {System.out.println(" 5 random letters");}
    	}
     
    }


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Printing random values from array list.

    Your can use Random class in java. Random (Java Platform SE 7 )

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Location
    Europe, Lithuania
    Posts
    10
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Printing random values from array list.

    There is no post.
    Last edited by Gasis; June 16th, 2014 at 01:11 PM. Reason: Personal mistake.

  4. #4
    Member Abhilash's Avatar
    Join Date
    Jun 2014
    Location
    Kolkata, West Bengal, INDIA
    Posts
    108
    My Mood
    Busy
    Thanks
    5
    Thanked 10 Times in 10 Posts

    Default Re: Printing random values from array list.

    Gasis : please review The Problem with Spoon-Feeding and comply.

    Thank you.

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Location
    Europe, Lithuania
    Posts
    10
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Printing random values from array list.

    Quote Originally Posted by Abhilash View Post
    Gasis : please review The Problem with Spoon-Feeding and comply.

    Thank you.
    Sorry, my bad. Thanks for info.

Similar Threads

  1. Help generating random permutations from array list
    By mactank13 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 2nd, 2012, 09:04 PM
  2. create an array of 99 random values; sorted and the printed
    By appoldk@yahoo.com in forum Java Theory & Questions
    Replies: 1
    Last Post: December 2nd, 2012, 04:57 PM
  3. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  4. Printing boolean values from an array
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 18th, 2010, 12:11 AM
  5. Doubt Regarding Printing an Array List
    By reeceypp in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 20th, 2010, 03:11 AM

Tags for this Thread