waltermilner

Untitled

Sep 23rd, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. public class Test {
  2.  
  3.   public static void main(String[] args) {
  4. // split a string at every third character..
  5.     String test = "12345678";
  6.     // iterate through string..
  7.     for (int i = 0; i < test.length(); i += 3) {
  8.       if (i + 3 > test.length()) // near the end?
  9.       {
  10.         System.out.println(test.substring(i));
  11.       } else // not near the end
  12.       {
  13.         System.out.println(test.substring(i, i + 3));
  14.       }
  15.     }
  16.   }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment