How to display every other letter of any word?
Closed due to the fact that off-topic participants Enikeyschik , 0xdb , aleksandr barakin , Sergey Glazirin , Denis Bubnov 17 Dec '18 at 8:16 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- Enikeyschik, 0xdb, aleksandr barakin, Sergey Glazirin, Denis Bubnov
- and what you can not? - michael_best
|
1 answer
It's simple. Use the chatAt(int index) function, which allows you to find a character by its number. Do not forget that the numbering starts from scratch.
String word = "Michael"; for(int i = 0; i < word.length() - 1; i++) { if ((i + 1) % 2 == 0) { System.out.println(word.charAt(i)); } } - Thank. But how to make it calculate the size of the string and write out every second letter? - Pavel Samsonenka
- @PavelSamsonenka check - michael_best
- Works. @michael_best thanks for the reply. - Pavel Samsonenka
- @PavelSamsonenka and thank you) - michael_best
|