0

Even & Odd Indices of a string

I have a query. If wanting to print/output ONLY the odd or even indices of a user input string (in Java) is there an inbuilt Java function to do so (similar to charAt()), or do I have to use a for loop?

3rd Dec 2018, 11:39 AM
Dakker
Dakker - avatar
1 Antwort
+ 3
There isn't something built in the Java libraries for this. You must either use a loop or recursion for it. The loop being the fastest and most understandable method. But, coding it via recursion would be a great learning experience.
3rd Dec 2018, 6:59 PM
John Wells
John Wells - avatar