Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: if problem with range of numbers

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    57
    My Mood
    Fine
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default if problem with range of numbers

    i want to show at the output that if the user input is in between 9.01 to 10.00 then it will print A ...and same i want to use it for some other values.. is there any way so that i can use a range in if statement ...or i have to write the complete set of nos in if statement ...
    plzzz helpppp...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: if problem with range of numbers

    The way to test for a range of numbers would be to use the > and the < operators. The numbers between 6 and 10 are > 6 and < 10.
    The operators take two operands. If you put them in ()s it will help you format them correctly.
    (x>6) && (x<10)

  3. The Following User Says Thank You to Norm For This Useful Post:

    deependeroracle (February 6th, 2012)

  4. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,180
    My Mood
    Hungover
    Thanks
    141
    Thanked 602 Times in 517 Posts

    Default Re: if problem with range of numbers

    Please do not post multiple copies of the same question. I've deleted your duplicate thread.

    Also, please read the link in my signature on asking questions the smart way. Especially the bit about using proper spelling and grammar.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. The Following User Says Thank You to KevinWorkman For This Useful Post:

    deependeroracle (February 6th, 2012)

  6. #4
    Junior Member
    Join Date
    Feb 2012
    Location
    Ireland
    Posts
    6
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: if problem with range of numbers

    Try something like this. Read up on your and(&&) and or(||) condisions. You will meet them very often.

    char letter = 'A';

    System.out.println("Enter a value between 9.01 and 10.00 ");
    //read in a value from user and store in double num;

    if (num > 9.00 && num <= 10.00)
    System.out.println(letter);

Similar Threads

  1. String index out of range?
    By oksmartypants in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 19th, 2012, 01:10 PM
  2. Help with my Range Finder programme
    By kidza12 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2011, 12:53 PM
  3. String Index out of range
    By petemyster in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 8th, 2010, 02:59 PM
  4. [SOLVED] Help; algorithm to determine 'range'
    By b_jones10634 in forum Algorithms & Recursion
    Replies: 13
    Last Post: August 24th, 2010, 04:57 PM
  5. set the slider's models (range)
    By chronoz13 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 28th, 2009, 10:59 PM