60 412
Assignments Done
98,2%
Successfully Done
In April 2018

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

Question #62298
How do you print every Nth character in Java?
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions