[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 dumb ass out

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: 15
Thread images: 1

File: idk.png (32KB, 1258x776px) Image search: [Google]
idk.png
32KB, 1258x776px
Can the java gods of /g/ help a beginner out, I'm trying to use double for loops to make a pattern-matching method looking for a sub-string in a string. The example would be lets say find how many times "-bdc" occurs in "abdcbybdc" with '-' being any letter and printing every match into an ArrayList. My issue is I loop through everything but once something doesn't match and I need to jump into the outer loop the index should be one less than it is.

tldr; this is why pajeets are taking over
>>
>>59546576
>needle
>haystack
what a pro lmao
>>
>>59546602
thanks lmfao
>>
>>59546576
>Initializing a Boolean with a condition

The fuck? Do people actually do this
>>
>>59546576
you gonna go blind from this theme eventually
>>
>>59546636
not trying to make it look clean just trying to make it work
>>
>>59546576
>>59546636
Anyways....
Looks like your changing the index in the other conditions,
Possibly just add one to the index when it doesn't match
>>
>>59546674
probably
>>
>>59546686
Sorry minus from I***
>>
>>59546703
this causes an infinite loop
>>
>>59546576

Learn how to properly indent you fucking retard.
>>
>>59546576
>java
>
>>
>>59546576
>every line at same level of indent
>variables names
>decrementing i

This is why companies hire H1Bs.
>>
>>59546576
>My issue is I loop through everything but once something doesn't match and I need to jump into the outer loop the index should be one less than it is.
Why are you changing i repeatedly in the inner loop? That makes things harder for you.

Also learn what break does.
>>
>>59546576
Hi OP,
You should not change value of your iterators(i,j) inside "for" loops. It is not what they were designed for.
Also try to rewrite this and take different approach.

needleIndex = 0;
for( int i = 0; i < haystack.length(); i++)
{
//match
if(match)
{
//check if that was last match
//if yes then break out of the
// loop
ret += haystack[i];
//increase needleIndex
}
else
{
needleIndex = 0;
ret = "";
}
}
Thread posts: 15
Thread images: 1


[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.