public class T1 {
public static void main(String[] args) {
char a[][] = {{'a','b','c','d','e','f'},{'g','h','i','j','k','l'},{'m','n','o','p','q','r'}};
char b[][] = new char[3][4];
for(int i=0;i<3;i++){
for(int j = 0; j < 4; j++){
b[i][j] = a[i][j];
System.out.print(b[i][j]);
}
System.out.println();
}
}
}
运行结果:
abcd
ghij
mnop
希望对你有用那个!
你好,按照你的要求代码如下,可以直接运行:
public class test {
public static void main(String[] args) {
String str = "a b c d e f g h i j k l m n o p q r";
for (int i = 0; i <= str.indexOf("d"); i += 2) {
for (int j = i; j < str.length(); j += 12) {
System.out.print(str.charAt(j) + " ");
}
System.out.println();
}
}
}
运行结果:
a g m
b h n
c i o
d j p
a b c d e f
g h i j k l
m n o p q r
转成2维数组,竖着看就是你要的