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: Random String

  1. #1
    Junior Member Gugubo's Avatar
    Join Date
    Jul 2013
    Posts
    24
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Random String

    Nevermind
    Last edited by Gugubo; November 30th, 2013 at 02:33 PM. Reason: Wrong section


  2. #2
    Junior Member Gugubo's Avatar
    Join Date
    Jul 2013
    Posts
    24
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Random String

    What's the easier way to get a random string?
    At the moment I would use:

    Random number = new Random();
    numberR = number.nextInt(2)+1;
    if (numberR==1){
        System.out.println("Hi.");
    }
    if (numberR==2){
      System.out.println("Hello.");
    }

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,574
    Thanks
    49
    Thanked 2,232 Times in 2,204 Posts

    Default Re: Random String

    Another way would be with a switch() statement.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,289
    My Mood
    Mellow
    Thanks
    191
    Thanked 668 Times in 655 Posts

    Default Re: Random String

    . . . or randomly choosing the index of a String array . . .

  5. #5
    Junior Member Gugubo's Avatar
    Join Date
    Jul 2013
    Posts
    24
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Random String

    Quote Originally Posted by GregBrannon View Post
    . . . or randomly choosing the index of a String array . . .
    yep, doing that now already. Apparently I forgot about arrays. Thanks anyway.

Similar Threads

  1. Storing random numbers into a String field
    By ajw1993 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 23rd, 2013, 10:44 AM
  2. RAndom string of Arabic text
    By saab613 in forum Java Theory & Questions
    Replies: 0
    Last Post: December 15th, 2011, 08:48 AM