日期:2014-05-20 浏览次数:20717 次
import javax.swing.JOptionPane;
public class PrintTheWord {
public static void main(String[] args) {
String s1 = JOptionPane.showInputDialog("Please enter string:");
String s2 = JOptionPane.showInputDialog("Please input the num:");
String[] ss = s1.split("");
int num = Integer.parseInt(s2);
for(int i = 1;i < ss.length;i += num){
for(int j = i;j < (i + num);j ++){
if(ss[j].matches("[\u4e00-\u9fa5]") && (j == (i + num - 1)) &&
(j != i)){
System.out.print("\n" + ss[j]);
} else{
System.out.print(ss[j] + "\t");
}
}
System.out.println("");
}
}
}
import javax.swing.JOptionPane;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
public class PrintTheWordRotate{
public static void main(String[] args) throws Exception{
String s1 = JOptionPane.showInputDialog("Please enter string:");
String s2 = JOptionPane.showInputDialog("Please input the num:");
int num = Integer.parseInt(s2);
System.out.println("输入的字符串是: "+s1+" 分割的长度是 "+num);
List<String> list = getTotal(s1,num); //得到划分的字符串集合。
System.out.println(list);
}
//得到分割的子串放容器返回
//
public static List<String> getTotal(String s, int copyNum) {
List<String> list = new ArrayList<String>();