Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
Like Tree2Likes

Thread: Two conditions in a while statement

  1. #21
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,095
    Rep Power
    4

    Default Re: Two conditions in a while statement

    Quote Originally Posted by loki88 View Post
    Eureka! I've found the solution.


    For some reason, I had to change my sum and product variables also in calculations. For a strange reason, at the end they are just zero. How comes that?
    Look at the place where you calculate the sum and product. Is that inside the loop? What values are number1 and number2. Do these change at the time of calculation?

  2. #22
    loki88 is offline Member
    Join Date
    Aug 2013
    Posts
    8
    Rep Power
    0

    Default Re: Two conditions in a while statement

    Oh, I thought if I did
    Java Code:
     int sum = number1 + number2;
    java would always use the current value of that number, thats why I use variables instead of plain numbers right?
    If I put the same line of code in the loop the value gets printed right. Thanks for pointing out the error.

  3. #23
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,095
    Rep Power
    4

    Default Re: Two conditions in a while statement

    When you type
    Java Code:
    int sum = number1 + number2;
    , you tell your program to caculate this. Nothing automatic, nothing fancy, just a one shot calculation. The reason you use variables in this case is to prevent typing in the same value in multiple different places.

  4. #24
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: Two conditions in a while statement

    Quote Originally Posted by JosAH View Post
    Why doesn't anyone apply a bit of math 101 anymore?
    I can't speak for the rest of the world, but speaking out of experience in the NL: math schooling nowadays sucks balls and is being phased out more and more. Only in the very beginning of my education did (basic) math really matter; even I, still quite young but not in my twenties anymore, have never been properly trained to apply math in the real world; I was only taught how to do some calculations which I quickly forgot again because I really don't need that on a daily basis.

    The only math that really stuck with me was self-taught; for game-development purposes. Because at least that is math I have learned to apply.
    Last edited by gimbal2; 08-22-2013 at 05:16 PM. Reason: I like to edit
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #25
    loki88 is offline Member
    Join Date
    Aug 2013
    Posts
    8
    Rep Power
    0

    Default Re: Two conditions in a while statement

    I follow gimbal2. I live in Belgium, very close to the Netherlands.

    I had basic math in highschool. After that, I got an university degree in criminology. I only needed statistics.
    Don't ask me anything on the math I have seen in high school. I simply didn't use it for years and I forgot everything.

  6. #26
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Two conditions in a while statement

    So far for the 'knowledge economy' in Belgium and the Netherlands. All 'hard' sciences are based on at least a bit of math and imho computer science is no exception. In this forum (and others) problems are 'solved' where a bit of math could've given a smarter, shorter, faster solution, but indeed, math is not en vogue anymore ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #27
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: Two conditions in a while statement

    Or just use the appropriate quadratic formula algorithm. Thought of that but I figured the OP wanted to play around with loops and random numbers.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #28
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: Two conditions in a while statement

    Quote Originally Posted by loki88 View Post
    @Jim29

    I tried to group the two conditions (sum and product in one boolean operator, but I get the error I can't use && with an INT variable)
    My earlier post said the following:
    "... a thru d are either boolean values or logical expressions"

    An int value is not a boolean value or logical expression.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #29
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Two conditions in a while statement

    Quote Originally Posted by jim829 View Post
    Or just use the appropriate quadratic formula algorithm.
    Erm, 'completing squares' is equivalent to the 'appropriate quadratic formula' only simpler to do by the wetware between your ears ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #30
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Two conditions in a while statement

    Quote Originally Posted by JosAH View Post
    Erm, 'completing squares' is equivalent to the 'appropriate quadratic formula' only simpler to do by the wetware between your ears ;-)

    kind regards,

    Jos

    He's a mathematician! Burn him!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #31
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: Two conditions in a while statement

    I guess I didn't explain myself clearly. By appropriate I meant appropriate for floating point calculations.

    Quadratic equation - Wikipedia, the free encyclopedia

    Regards,
    Jim

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #32
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Two conditions in a while statement

    Quote Originally Posted by KevinWorkman View Post
    I'm not a mathematician, you dressed me up like that and put on that nose!

    kind regards,

    Jos Ni! Ni! Ni! ;-)
    KevinWorkman and gimbal2 like this.
    cenosillicaphobia: the fear for an empty beer glass

Page 2 of 2 FirstFirst 12

Similar Threads

  1. How to avoid many if else conditions
    By Addymails in forum New To Java
    Replies: 9
    Last Post: 03-22-2012, 01:39 PM
  2. Problem in while conditions
    By davie89 in forum New To Java
    Replies: 2
    Last Post: 03-20-2012, 01:37 AM
  3. Asking for a username with conditions
    By ScentOfAWookie in forum New To Java
    Replies: 2
    Last Post: 03-20-2009, 06:53 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
  •