/home/wpollock1/public_html/restricted/Java1/EveryNth.java

/*
   Fizz-Buzz problem from codingbat.com (http://codingbat.com/prob/p196441):

   Given a non-empty string and an int N, return the string made starting with
   char 0, and then every Nth char of the string.  So if N is 3, use char 0, 3,
   6, ... and so on.  N is 1 or more.

   Examples:

      everyNth("Miracle", 2) → "Mrce"
      everyNth("abcdefg", 2) → "aceg"
      everyNth("abcdefg", 3) → "adg"

   Solution written 4/2015 by Wayne Pollock, Tampa Florida USA.

   Note: this solution assumes BMP Unicode (<64Ki) only.  For full
   Unicode support, replace line 30 with:
       int positionInString = str.offsetByCodePoints(0,i);
       sb.append( str.codePointAt(positionInString) );
*/

class EveryNth {
   public static void main ( String [] args ) {
      System.out.println( everyNth( args[0], Integer.parseInt(args[1]) ));
   }

   public static String everyNth ( String str, int n ) {
      StringBuilder sb = new StringBuilder();
      for ( int i = 0; i < str.length(); i += n ) {
         sb.append( str.charAt(i) );
      }
      return sb.toString();
   }
}