posted 3 months ago

I want to find all odd numbers between two numbers.

For example: [3, 9] all odd numbers are: 3, 5, 7, 9.

I created a solution but I don't know how to compute number of odd numbers between 2 numbers.

Probably, sure there is a formula to calculate number of odd numbers.

}

Thanks,

For example: [3, 9] all odd numbers are: 3, 5, 7, 9.

I created a solution but I don't know how to compute number of odd numbers between 2 numbers.

Probably, sure there is a formula to calculate number of odd numbers.

}

Thanks,

OCAJP 7

Ryan McGuire

Ranch Hand

Posts: 1143

9

posted 3 months ago

I see one issue at line 26. What index of odd1 are you assigning to each time? Try working through an example by hand and see if that's what you wanted.

Bigger picture... It would really help us help you if you say what behavior you're seeing now. Do you get any output? If so, what? Are any exceptions being thrown?

As for calculating the count of odd numbers in a range...

It seems to me that the count of odds is approximately equal to the size of the range divided by 2. The actual result will within 1 of that result. For instance, the count of odd numbers between 50 and 75 is probably within 1 of 25/2 - 12 or 13. The detail of whether to add something to the range size divided by 2 is related to whether the high and low numbers are even or odd.

What can you put in those "other columns" so that you arrive at the result in the final column?

Bigger picture... It would really help us help you if you say what behavior you're seeing now. Do you get any output? If so, what? Are any exceptions being thrown?

As for calculating the count of odd numbers in a range...

It seems to me that the count of odds is approximately equal to the size of the range divided by 2. The actual result will within 1 of that result. For instance, the count of odd numbers between 50 and 75 is probably within 1 of 25/2 - 12 or 13. The detail of whether to add something to the range size divided by 2 is related to whether the high and low numbers are even or odd.

What can you put in those "other columns" so that you arrive at the result in the final column?

posted 3 months ago

My code is OK, but I don't want to display 0, if the number is even.

I found a formula for odd numbers and I want to create a new array only for odd numbers.

I get the exception and is normal:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4

at oddnumbers.OddNumbers.oddNumbers1(OddNumbers.java:55)

at oddnumbers.OddNumbers.main(OddNumbers.java:70)

C:\Users\andad\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1

BUILD FAILED (total time: 0 seconds)

But how can resolve this exception?

I found a formula for odd numbers and I want to create a new array only for odd numbers.

I get the exception and is normal:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4

at oddnumbers.OddNumbers.oddNumbers1(OddNumbers.java:55)

at oddnumbers.OddNumbers.main(OddNumbers.java:70)

C:\Users\andad\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1

BUILD FAILED (total time: 0 seconds)

But how can resolve this exception?

OCAJP 7

Ryan McGuire

Ranch Hand

Posts: 1143

9

Don't get me started about those stupid light bulbs. |