Forums Register Login

Array Method

+Pie Number of slices to send: Send
I'm writing a method that takes a single parameter which is an array of ints and returns the number of elements in that array that are greater than the first element. My code is as follows:



When I enter into the method call new int[] {1,2,3}, it returns 2 which is correct. But when I enter in the method call new int[] {2,1,3}, it again returns 2 when it was expected to return 1. I can't figure out why it's doing this.

Thanks.
+Pie Number of slices to send: Send
there is a semi-colon at the end of if statement remove it and it will work fine

+Pie Number of slices to send: Send
Wow, I didn't even notice that...must have typed that by accident. Thanks!

Amy
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 571 times.
Similar Threads
Getting wrong answers for conversion
next() cannot override next() in my abstract list.
Finding Nth Largest element of an array without sorting
Incompatible types
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:10:29.