View difference between Paste ID: cxTz36JG and NmjLVNed
SHOW: | | - or go back to the newest paste.
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);
19+
  System.out.println(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)
24+
public static String 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);
29+
30
return s3;
31
// >>>>>> Your Java Methods end here <<<<<<
32
}