Results 1 to 3 of 3

Thread: Loop

  1. #1
    Kartiky14 is offline Member
    Join Date
    Mar 2012
    Posts
    10
    Rep Power
    0

    Default Loop

    long number = 5572331, result =0;
    do
    {
    result *=10;
    int digit = number %10;
    result+=digit;
    number/=10;
    }while(number) <----- what are we checking over here??? ---- (Is it that it's getting reduced to a zero so ultimately it will be false ??_)

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default Re: Loop

    the code will not compile, since int is not a boolean.

  3. #3
    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 Re: Loop

    It would work in C or C++ but Java is more picky about it, so you have to change your while-loop condition to number != 0.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 2
    Last Post: 11-07-2011, 02:25 AM
  2. Replies: 1
    Last Post: 10-01-2011, 02:12 AM
  3. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 05:46 PM
  4. [Q] Loop issue (while loop)
    By iriscience in forum New To Java
    Replies: 9
    Last Post: 01-31-2011, 04:21 PM
  5. Replies: 5
    Last Post: 04-30-2010, 05:05 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
  •