Results 1 to 3 of 3
  1. #1
    coolecho is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default Assignment to boolean

    Hi,

    I am trying to use a boolean type for a result of an expression that in int results in 1 or 0.

    int isEven = x % 2;
    boolean b = (boolean) isEven; // tried cast but is illegal

    I need isEven to end up as true or false.

    Thanks,

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Do this:

    Java Code:
    boolean b= isEven == 0;
    kind regards,

    Jos

  3. #3
    coolecho is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Boolean problems
    By Chasingxsuns in forum New To Java
    Replies: 2
    Last Post: 09-15-2009, 10:57 PM
  2. transfer boolean to 1's and 0's
    By Nikohw in forum Java Applets
    Replies: 5
    Last Post: 09-12-2009, 09:05 PM
  3. boolean to string
    By otoro_java in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 05:31 AM
  4. boolean variables
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-31-2007, 04:58 AM
  5. Boolean Expression
    By ritwik07 in forum New To Java
    Replies: 3
    Last Post: 07-11-2007, 04:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •