# Problem that I can't solve...

• 11-16-2011, 01:16 AM
Wing.Sham
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.
• 11-16-2011, 01:26 AM
KimChi93
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.
• 11-16-2011, 01:28 AM
Wing.Sham
Re: Problem that I can't solve...
Quote:

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??
• 11-16-2011, 01:33 AM
KimChi93
Re: Problem that I can't solve...
I can't see why not, but either way should work :D:
• 11-16-2011, 01:35 AM
Junky
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?
• 11-16-2011, 01:37 AM
Wing.Sham
Re: Problem that I can't solve...
Quote:

Originally Posted by KimChi93
I can't see why not, but either way should work :D:

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.
• 11-16-2011, 01:40 AM
Wing.Sham
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??
• 11-16-2011, 02:12 AM
KimChi93
Re: Problem that I can't solve...
You can put a nice big IF around the while statement :D:
• 11-16-2011, 02:21 AM
Wing.Sham
Re: Problem that I can't solve...
Quote:

Originally Posted by KimChi93
You can put a nice big IF around the while statement :D:

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 :)
• 11-16-2011, 02:31 AM
Junky
Re: Problem that I can't solve...
Pseudocode
Code:

```declare boolean while input is invalid {     get input     if input is valid {         change boolean     } else {         display error message     } }```