How would I combine these two lines?

I need to find a number between 1-19 that is an odd number.

I know the two lines would be:

1
2
3
if (n>=1 || n<=19) {
//do stuff
}


And...

1
2
3
if (n%2!=0){
//do stuff
}


But, what I am confused by is how I would add these lines together to make sure both are met?

Would it be something like this?

1
2
3
if (n>=1 || num<=19) && (n%2!=0) {
//do stuff
}
Last edited on
if (n>=1 || n<=19) {

This is incorrect... as this statement will ALWAYS be true (a number is always going to be either >=1 or <= 19).

You probably meant to use && here, instead of ||.



if (n>=1 || num<=19) && (n%2!=0) {

You have the right idea, yes. But you need to enclose the entire condition in parenthesis.... and you'll want to fix that || issue. So this should work:

if( (n>=1 && num<=19) && (n%2!=0) ) {
@Disch, Thanks for the help, everything is up and working.
Topic archived. No new replies allowed.