Advertisement
Guest User

Untitled

a guest
Jul 11th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import java.util.*; public class W1C3 {public static void main (String[] args) {while (JPL.test()) {
  2.  
  3. ////////////////////////////// PROBLEM STATEMENT //////////////////////////////
  4. // Given a non-empty string and an int N, print the string made starting //
  5. // with char 0, and then every Nth char of the string. So if N is 3, use //
  6. // char 0, 3, 6, ... and so on. N is 1 or more. Implement a method to build //
  7. // the result string. //
  8. // "Miracle", 2 -> "Mrce" //
  9. // "abcdefg", 2 -> "aceg" //
  10. // "abcdefg", 3 -> "adg" //
  11. ///////////////////////////////////////////////////////////////////////////////
  12.  
  13. // >>>>>> Your Java Code Fragment starts here <<<<<<
  14. Scanner keyboard = new Scanner(System.in);
  15.  
  16. String s1 = keyboard.next();
  17. int n = keyboard.nextInt();
  18.  
  19. answerYou(s1,n);
  20. // >>>>>> Your Java Code Fragment ends here <<<<<<
  21. }}
  22. // >>>>>> Your Java Methods start here <<<<<<
  23.  
  24. public static void answerYou(String s1, int n)
  25. {
  26. String s3 ="";
  27. for(int i = 0; i < s1.length();i+=n)
  28. s3 += s1.charAt(i);
  29. System.out.println(s3);
  30. }
  31.  
  32. // >>>>>> Your Java Methods end here <<<<<<
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement