Results 1 to 4 of 4

Thread: If else error

  1. #1
    ice_breaker is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default If else error

    I wanna do the code as i is divisible by 3,5, or 7, then print foo, bar and baz. But it shows errors. Please advise. Thanks

    public static void main(String[] args) {
    int i;
    for(i=1;i<=50;i++)
    {
    if(i%3=0)
    {
    System.out.println("Foo");
    } else if (i%5=0)
    {
    System.out.println("Bar");
    } else if (i%7=0)
    {
    System.out.println("Baz");
    }
    else
    {
    System.out.println("Wrong");
    }

    }


    }
    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    = is an assignment, you need == to compare int values.

    And next time you post, use code tags and post the exact error message(s) you get.

    Read the link in my signature.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    ice_breaker is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default

    I got it. Thanks for letting me know.

  4. #4
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    I wonder if it is possible to write this code using the switch stament?

    And if it can be written, whether it is useful to write with switch stament?

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2010, 02:53 PM
  2. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  3. Replies: 1
    Last Post: 10-26-2009, 05:38 PM
  4. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  5. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 05:28 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
  •