public class Change{
public static void main(String[] args){
int Co=30; //排序到多少位?
int[][] Arr=new int[5][]; //定义不规则数组
int integer=0;//用来计数的
for (int i = 0; i < 5; i++) {
Arr[i] =new int[Co/5];
for (int j = 0; j < Co/5; j++) {
Arr[i][j]=integer++;
}
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < Co/5; j++) {
System.out.print(","+Arr[i][j]);
}
System.out.println();
}
}
}
效果
,0,1,2,3,4,5
,6,7,8,9,10,11
,12,13,14,15,16,17
,18,19,20,21,22,23
,24,25,26,27,28,29
写错了,,,特来更正
=========================================================================
public class Change{
public static void main(String[] args){
int[][] Arr=new int[5][];
int Co=30;
int integer=0;
for (int i = 0; i < 5; i++) {
Arr[i] =new int[Co/5];
}
for (int i = 0; i < Co/5; i++) {
for (int j = 0; j < 5; j++) {
Arr[j][i]=integer++;
}
}
for (int i = 0; i < Co/5; i++) {
for (int j = 0; j < 5; j++) {
System.out.print(","+Arr[j][i]);
}
System.out.println();
}
}
}
效果
,0,1,2,3,4
,5,6,7,8,9
,10,11,12,13,14
,15,16,17,18,19
,20,21,22,23,24
,25,26,27,28,29
public static void main(String[] args) {
int[][] a = new int[4][5];
int[] b = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
int k = b.length - 1;
for(int i = a.length - 1; i >= 0; i--) {
for(int j = a[i].length - 1; j >= 0; j--) {
a[i][j] = b[k];
k--;
}
}
for(int i = 0; i < a.length; i++) {
for(int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j]+""+'\t'); // '\t'这个转义符就是左对齐的作用;
}
System.out.println();
}
}
}
/**和前几楼的有点不一样,看看这个符合要求不,输出格式也可以用System.out.printf(..)*/
public class Test_1 {
/**
* @param args
*/
public static void main(String[] args) {
int i, j, k = 0;
int[][] a = new int[4][5];
for (i = 0; i < 4; i++) {
for (j = 0; j < 5; j++, k++) {
a[i][j] = k;
}
}
for (i = 0; i < 4; i++) {
System.out.println();
for (j = 0; j < 5; j++) {
System.out.print(" " + a[i][j]);
}
}
}
}
public class test {
public static void main(String[] args) {
int[] lit = new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
for (int i = 0 ; i < lit.length ; i++) {
System.out.print(i+" ");
if((i+1)%5 == 0) System.out.println();
}
}
}
public class Test {
public static void main(String[] args) {
int i, j;
int[][] arr = new int[4][5];
for(i=0; i<4; i++){
for(j=0; j<5; j++){
arr[i][j] = i * 5 + j;
}
}
for(i=0; i<4; i++){
for(j=0; j<5; j++){
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}