Answer to Question #62298 in Java | JSP | JSF for Ann

Question #62298
How do you print every Nth character in Java?
1
Expert's answer
2016-09-29T14:09:04-0400
public class Printer {
public static void printEveryNthCharacter(String str, int n) {
if (str.length() < n) {
System.out.println("N value is too large");
}
else {

String out = "";
for (int i = n - 1; i < str.length(); i += n) {
out += str.charAt(i);
}
System.out.println(out);
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS