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

1. Member
Join Date
Nov 2011
Posts
12
Rep Power
0

## 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 01:18 AM.

2. ## 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. Member
Join Date
Nov 2011
Posts
12
Rep Power
0

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

Originally Posted by KimChi93
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. ## Re: Problem that I can't solve...

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

5. ## 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?

6. Member
Join Date
Nov 2011
Posts
12
Rep Power
0

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

Originally Posted by KimChi93
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. Member
Join Date
Nov 2011
Posts
12
Rep Power
0

## 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. ## Re: Problem that I can't solve...

You can put a nice big IF around the while statement

9. Member
Join Date
Nov 2011
Posts
12
Rep Power
0

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

Originally Posted by KimChi93
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. ## 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
}
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•