[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Need help writing a simple code in Java. Basically what the code
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 13
Thread images: 1
File: java-logo.jpg (36 KB, 651x400) Image search: [Google]
java-logo.jpg
36 KB, 651x400
Need help writing a simple code in Java.
Basically what the code should do is analyze a string and output the first and second word. By word I mean a string of adiacent alphabetic letters.
For example in the string " Hello, my name is Luca ", it shuld return Hello and my.
In the string " Hel!lo" it should return Hel and lo.
The challenge consists in not using nor loops nor if conditions, and the code must include .indexOf() and .substring()
>>
Anyone?
>>
>>>/r/homeworkhelp
>>
>>55139415
thanks m8
>>
if you can't do this, you should just stop while you're behind.

literally use google or go to the programming general thread
>>
>>55139305
Use char
>>
YOU HAVE TO GO STACK
>>
Just use .split(" ") or something.
There are much better sources out there that have answers to these kind of homework questions
>>
Don't even use google. Just fucking think it through. You don't even need to use the string functions for it. Do it like an array. Iterate over the string store the sequence of alphabetical characters. The first one that doesn't satisfy that condition is where you stop for your first "word" then continue from where you left off and store the next "word".

This is a naive solution, but whatever. You'll need to handle cases like if the first character is not alphabetical or when you have multiple non alphabeticals between words. But those are easy to handle.
>>
>>55139678
>The first one that doesn't satisfy that condition
>condition

no loops or conditions
>>
>>55139305
Google how to regex
>>
>>55139763
Oh fuck you have to use the string libraries and no looping, didn't read the full post. Then yeah probably can't help, read the oracle API for strings (I don't know Java well) and split the string up into subparts, based on the restrictions for words. If I remember correctly the string API has almost everything you need to avoid iterating over it yourself.
>>
>>55139840
This is the easiest way
Thread replies: 13
Thread images: 1

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.