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
    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 03:33 PM. Reason: Wrong section


  2. #2
    Junior Member
    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
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 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,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Random String

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

  5. #5
    Junior Member
    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, 09:48 AM