Results 1 to 13 of 13
  1. #1
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default conditional statement

    How can I write a conditional statement that will find the smallest integer among five integers that I will input?


    I need to do this with if else statement. I'm attending in our java class for almost two weeks already and I must admit that I'm not yet good at it. So please help me on this matter. I already write some code under javax.swing library.. but I really having a problem with the conditional statement. I hope someone would help :)
    Heart is the only broken thing that still works.

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    just write a method for this

    like a

    int getMin(int five);
    To refresh your signt please watch my signature ;)
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    write a conditional statement that will find the smallest integer among five integers
    Are the requirements that tests be in a single statement? It's possible but will require a very long statement. No one programs that way.
    The most common way is with a loop and an array with a simple if() statement.

  4. #4
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    but I will only use "if else" statement.


    The output is like:

    Enter 1st integer: ___
    Enter 2nd integer: ___
    Enter 3rd integer: ___
    Enter 4th integer: ___
    Enter 5th integer: ___


    The smallest integer is ____
    Heart is the only broken thing that still works.

  5. #5
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Are the requirements that tests be in a single statement? It's possible but will require a very long statement. No one programs that way.
    The most common way is with a loop and an array with a simple if() statement.

    please take a look with the sample out above.....
    Heart is the only broken thing that still works.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    As Norm suggests, put the numbers in an array and loop through the array with a for loop checking for the lowest number. Let's see you give this a try, show us the code you've created and we can go from there.

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

    Default

    Quote Originally Posted by Webuser View Post
    To refresh your signt please watch my signature ;)
    Why do you keep on begging for 'rep' points? Your answers aren't outstanding and your way of begging looks more like phishing. Please stop that silly behaviour.

    kind regards,

    Jos

  8. #8
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Quote Originally Posted by JosAH View Post
    Why do you keep on begging for 'rep' points? Your answers aren't outstanding and your way of begging looks more like phishing. Please stop that silly behaviour.

    kind regards,

    Jos
    You should see his attempts to spam your inbox if you don't rep him for his cursory help.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Lil_Aziz1 View Post
    You should see his attempts to spam your inbox if you don't rep him for his cursory help.
    Is that so? Is he actually *demanding* those silly 'rep' points? If I were you I'd report him or ask one of the moderators for a ban.

    kind regards,

    Jos

  10. #10
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Heh, I do so enjoy reading hijacked threads :)

    Back to the OPs post, the array with a for loop is the best way to do it. When I do it, I declare a variable outside the for loop to hold the lowest number (set it to Integer.MAX_VALUE or it may not be reset later). Then, for each iteration of the loop, it checks whether the value is less than that variable, and if it is, sets the variable to the new lowest value.

    Hopefully this helps explain the idea a bit.

    P.S. I can't even understand the last sentence webuser wrote ;) And really, what does rep power even DO?
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  11. #11
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Thumbs up

    Quote Originally Posted by JosAH View Post
    Why do you keep on begging for 'rep' points? Your answers aren't outstanding and your way of begging looks more like phishing. Please stop that silly behaviour.

    kind regards,

    Jos
    JosAH, I dearly hope you know the interface coding style :rolleyes:

    Quote Originally Posted by Norm
    The most common way is with a loop and an array with a simple if() statement.
    Norm, you read my post and signature correctly!

    + 1 for Norm

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Webuser View Post
    JosAH, I dearly hope you know the interface coding style :rolleyes:
    That is a non sequitur to my remark.

    Jos

  13. #13
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Quote Originally Posted by blindfolded916 View Post
    How can I write a conditional statement that will find the smallest integer among five integers that I will input?


    I need to do this with if else statement. I'm attending in our java class for almost two weeks already and I must admit that I'm not yet good at it. So please help me on this matter. I already write some code under javax.swing library.. but I really having a problem with the conditional statement. I hope someone would help :)
    to solve read this thread

    cant get highest and lowest to display
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

Similar Threads

  1. Lucene as Conditional Evaluator / Indexer?
    By cuebei in forum Lucene
    Replies: 0
    Last Post: 01-11-2010, 07:36 PM
  2. Replies: 1
    Last Post: 10-29-2009, 11:48 AM
  3. JSP Help - Conditional Meta Tags
    By jakavan in forum New To Java
    Replies: 0
    Last Post: 12-08-2008, 06:34 PM
  4. how to do conditional looping?
    By chennee72 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-09-2008, 12:38 PM
  5. JFrame Conditional Close
    By hemanthjava in forum AWT / Swing
    Replies: 10
    Last Post: 06-29-2008, 07:49 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
  •