Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By Junky

Thread: Problem that I can't solve...

  1. #1
    Wing.Sham is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default Problem that I can't solve...

    Hi guys, I want input angle a,b,c that is in the range of 0-180. Otherwise, it would not make a quadrilateral shape. I have made an attempt using an 'if' statement, but it doesn't do what I want it to.

    note that Min = 0 Max=180.

    Here's a piece of my code:

    System.out.println("Enter Angle A = ");
    int AA = input.nextInt();
    if ((AA < MIN) && (AA > MAX)); {
    System.out.println("This is not in the range.");
    }

    Say i input 999 for angle A, it inputs it and shows a message saying "This is not in the range." - YES!
    However, I want another "int AA = input.nextInt();" to input again so the user can input a number again and replaces the previous number. I have tried this and it doesn't work and get errors. :(

    thanks.
    Last edited by Wing.Sham; 11-16-2011 at 12:18 AM.

  2. #2
    KimChi93's Avatar
    KimChi93 is offline Programmer
    Join Date
    Nov 2011
    Location
    USA BABY
    Posts
    9
    Rep Power
    0

    Default Re: Problem that I can't solve...

    I suggest you place a forloop around this that will keep running until the user enters a value that is within the range. Then write the else coding for what you want it to do if the angle is within the range.

  3. #3
    Wing.Sham is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default Re: Problem that I can't solve...

    Quote Originally Posted by KimChi93 View Post
    I suggest you place a forloop around this that will keep running until the user enters a value that is within the range. Then write the else coding for what you want it to do if the angle is within the range.
    Ah i see. Is it possible to use while statement??

  4. #4
    KimChi93's Avatar
    KimChi93 is offline Programmer
    Join Date
    Nov 2011
    Location
    USA BABY
    Posts
    9
    Rep Power
    0

    Default Re: Problem that I can't solve...

    I can't see why not, but either way should work

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: Problem that I can't solve...

    Yes a while loop would be best. Also how can a value be less than 0 AND greater than 180?
    KimChi93 likes this.

  6. #6
    Wing.Sham is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default Re: Problem that I can't solve...

    Quote Originally Posted by KimChi93 View Post
    I can't see why not, but either way should work
    its just that i tried using while statement. And using ''int AA = input.nextInt();'' again I get an error because the constructor is not at the top, it's below the code I have showed in my post. If I moved it at the top, I would get tons of errors.

  7. #7
    Wing.Sham is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default Re: Problem that I can't solve...

    The thing is... I have not started using loops in java. We start that tomorrow. I'll give it a try and see if it works. Would I have to use ++ to increment??

  8. #8
    KimChi93's Avatar
    KimChi93 is offline Programmer
    Join Date
    Nov 2011
    Location
    USA BABY
    Posts
    9
    Rep Power
    0

    Default Re: Problem that I can't solve...

    You can put a nice big IF around the while statement

  9. #9
    Wing.Sham is offline Member
    Join Date
    Nov 2011
    Posts
    12
    Rep Power
    0

    Default Re: Problem that I can't solve...

    Quote Originally Posted by KimChi93 View Post
    You can put a nice big IF around the while statement
    Alright. I'll do my best. Because I have to submit it tomorrow, it doesn't matter if this validation doesn't work, at least I got most of it working. I have more assignments coming up. So I will do better on those. Thanks Kimchi :)

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: Problem that I can't solve...

    Pseudocode
    Java Code:
    declare boolean
    while input is invalid {
        get input
        if input is valid {
            change boolean
        } else {
            display error message
        }
    }

Similar Threads

  1. Solve JVM Problem
    By pedroffbarbosa in forum Advanced Java
    Replies: 8
    Last Post: 11-28-2011, 11:35 PM
  2. Need help to solve my problem
    By Copro in forum New To Java
    Replies: 4
    Last Post: 08-21-2009, 04:26 AM
  3. Help me to solve problem
    By mansoorhacker in forum Forum Guides
    Replies: 8
    Last Post: 01-24-2009, 06:29 PM
  4. Solve my Problem
    By kyo in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 02:22 PM
  5. Help me to solve problem
    By mansoorhacker in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 08:15 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
  •