- public class Rows {
- public static void main(String[] args) {
- int arr[][] =new int[5][5];
- int i = 0;
- int j = 0;
- int count = 1;
- boolean flag = true;
- for(int num = 1;num<=25;num++){
- arr[i][j]=num;
-
- if(flag){
- j++;
- if(j>5-count){
- i++;
- j--;
- if(i>5-count){
- flag=false;
- i--;
-
- }
- }
- }
- if(!flag){
- j--;
- if(j<count-1){
- i--;
- j++;
- if(i<count){
- flag=true;
- i++;
- j++;
- count++;
- }
- }
-
- }
-
- }
- for(i=0;i<5;i++){
- for(j=0;j<5;j++){
- System.out.print(arr[i][j]+"\t");
- }
- System.out.println();
- }
- }
- }[code]1 2 3 4 5
- 16 17 18 19 6
- 15 24 25 20 7
- 14 23 22 21 8
- 13 12 11 10 9
复制代码 [/code] |