Results 1 to 3 of 3
  1. #1
    BeardedCamel is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Thumbs up Java OR operator || help!

    Hi there!
    Im new to java and making a Scottish name maker to help me learn. It uses scanner scan to input your name and then sticks a scottish surname on the end of it :-) I want to randomize the surnames using OR, but its not working :-( I think i need some help!
    The code i am using is:
    Java Code:
    System.out.print(name + " MacEwen" || " MacAlsiter" || " MacDonald" || " Douglas");
    Thanks in advance for the help!

  2. #2
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    354
    Rep Power
    5

    Default Re: Java OR operator || help!

    OR is a logical operator. The System.out.println accepts accepts an object as its arguments (like a string).
    Last edited by sehudson; 09-19-2011 at 09:00 PM.

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Java OR operator || help!

    System.out.print(name + Arrays.asList(" MacEwen" , " MacAlsiter" , " MacDonald" ," Douglas").get(new Random().nextInt(4)));
    (or Collections.shuffle ...or or or....)
    :D

Similar Threads

  1. operator - cannot be applied to java.lang.String,int
    By cc11rocks in forum AWT / Swing
    Replies: 0
    Last Post: 02-11-2011, 03:33 AM
  2. Replies: 2
    Last Post: 11-26-2010, 02:12 AM
  3. Replies: 3
    Last Post: 12-01-2008, 05:40 AM
  4. Replies: 4
    Last Post: 11-27-2008, 06:09 AM
  5. [SOLVED] Java operator overloading
    By tim in forum New To Java
    Replies: 5
    Last Post: 06-26-2008, 07:35 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
  •