[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Help a nigga with his coding assignment

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 23
Thread images: 3

File: Capture.png (17KB, 1037x583px) Image search: [Google]
Capture.png
17KB, 1037x583px
Any idea how i can stop this from throwing an index out of bound exception in the second for loop. Assuming the array has integers in it.
>>
File: 1475287073391.jpg (40KB, 720x602px) Image search: [Google]
1475287073391.jpg
40KB, 720x602px
>>58678094
>>
use spacebar you double nigger
>>
>>58678094
He wrote pos<length, Not pos<=length
>>
If all your values Match to Foo, your match integer will grow bigger than the Array.
>>
>>58678094
maybe you should drop out
>>
>>58678060
The second for loop is useless. You probably have an infinite loop because the condition is never met then you start indexing out of bounds indices.
>>
>>58678060
>useless if statement
You're better off shoplifting, Jamal.
>>
>>58678187
Heh, yeah.

Instead,

return ans >= k;
>>
>>58678204
its a Boolean return i need to check if their is consecutive integers (one after the other). The if statement is to check how many times there are consecutive integers and if its at least the the or equal to the provided number (k)
>>
>>58678060
what font is that?
>>
>>58678256
Yes. ans <= k is a Boolean. You are evaluating a Boolean, then returning a hard coded Boolean.

Instead, you can just return the evaluation directly.

This does not solve the array out of bounds issue though, you just save one evaluation and 5 lines of code (if you consider just a brace a line of code)
>>
>>58678346
I see what you mean thanks for the advice, im going to go drop out though
>>
>>58678060
What are you trying to achieve with this code?
>>
>>58678060
Your codestyle is awful. Consider using some lints.
>>
>>58678410
Try looking at the code you wrote when you first started.
>>
>>58678060
foo is uninitialized. This means it can be anything from -INT_MAX to +INT_MAX. Most of these values are out of bounds.
>>
Color theme OP?
>>
>>58678060
the first for loop is useless. You will only ever check the first element and then return.
>>
>>58678571
>foo = values[pos]
>>
>>58678453
What are you trying to do exactly?

>>58678393
>drop out
Don't be a pussy.
>>
You're not checking wether you're still in bonds in the second loop, use "values[match]==foo && match<values.length" in the loop condition.
>>
>>58678617
>>58678305

Color Theme is sublime text monokai extended
Appearance is MoonRise (standalone)
Thread posts: 23
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.