0

I need to write a loop to go through a string and retrieve alternate characters from index positions. Then append the characters to another string and then print (eg. "pleasehelp" = "peshl")

I have hit a wall and lack any sort of know how to push through... what have I got myself into? All I have is below.

string sentence = "please help";

char[] charSentence = sentence.toCharArray();

for (sentence);

Edited by addlou: n/a

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by Momerath
0
string sentence = "please help";
char[] charSentence = sentence.toCharArray();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < charSentence.length; i += 2) {
    builder.Append(charSentence[i]);
}
println(builder.toString());
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.