Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*; public class W1C3 {public static void main (String[] args) {while (JPL.test()) {
- ////////////////////////////// PROBLEM STATEMENT //////////////////////////////
- // Given a non-empty string and an int N, print 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. Implement a method to build //
- // the result string. //
- // "Miracle", 2 -> "Mrce" //
- // "abcdefg", 2 -> "aceg" //
- // "abcdefg", 3 -> "adg" //
- ///////////////////////////////////////////////////////////////////////////////
- // >>>>>> Your Java Code Fragment starts here <<<<<<
- Scanner keyboard = new Scanner(System.in);
- String s1 = keyboard.next();
- int n = keyboard.nextInt();
- System.out.println(answerYou(s1,n));
- // >>>>>> Your Java Code Fragment ends here <<<<<<
- }}
- // >>>>>> Your Java Methods start here <<<<<<
- public static String answerYou(String s1, int n)
- {
- String s3 ="";
- for(int i = 0; i < s1.length();i+=n)
- s3 += s1.charAt(i);
- }
- return s3;
- // >>>>>> Your Java Methods end here <<<<<<
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement