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?
>>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