How do you print every Nth character in Java?
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!
Learn more about our help with Assignments:
JavaJSPJSF