import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static String reshape(int n, String str){
if(str==null){
return null;
}
StringBuilder reshapeString = new StringBuilder();
char[] stringToChar = str.replaceAll(" ", "").toCharArray();
int j= 0;
for(int i=0; i<stringToChar.length;i++){
j++;
reshapeString.append(stringToChar[i]);
if(j==n && i<stringToChar.length-1){
reshapeString.append("\n");
j=0;
}
}
return reshapeString.toString();
}
public static void main(String[] args) {
System.out.println(reshape(3,"abc de fghi"));
System.out.println(reshape(2,"1 23 456"));
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: