Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static void main(String[] args) {
- // split a string at every third character..
- String test = "12345678";
- // iterate through string..
- for (int i = 0; i < test.length(); i += 3) {
- if (i + 3 > test.length()) // near the end?
- {
- System.out.println(test.substring(i));
- } else // not near the end
- {
- System.out.println(test.substring(i, i + 3));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment