# Thread: simple program help

1. Member
Join Date
Feb 2014
Posts
2
Rep Power
0

## simple program help

I'm suppose to be doing a factorial of a number within certain constraints (say a number between 5 and 10).
I get the factorial easy enough but I'm getting it for every number no matter what I put in.
textio is used instead of scanner for our class.

Java Code:
```public class Factorial {
public static void main(String[] args) {
int max = 0;
int x = 0;
long y = 0;
System.out.println("Enter a number between 5 and 10.");
max = TextIO.getlnInt();
if (max > 4 || max <= 10) {
y = max;
for (x = 1; x <= max-1; x++){
y = y * x;

}
TextIO.putln(y);
}

}
}```
Ideally I should be able to put in a number outside the range and the program will do nothing until I put a number in with the correct value. Thanks for the help.

2. ## Re: simple program help

The problem is in your if-statement: "max > 4 || max <= 10"

Consider my input: 3. Is it > 4? False! Is it <=10? True! So the condition is true since false || true == true.
Consider my input: 13. Is it > 4? True! Is it <=10? False! So the condition is true since true || false == true.

Replace the || with && and it will work as false && true == false.

3. Member
Join Date
Feb 2014
Posts
2
Rep Power
0

## Re: simple program help

Thank you! I dont know why I didn't immediately catch that.. or why I didn't use && to begin with.

#### Posting Permissions

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