Guest User

Untitled

a guest
Feb 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. public class something
  2. {
  3.    public static void main (String [] args)
  4.    {
  5.    int number = 1;
  6.    int count = 0;
  7.    int columns = 1;
  8.    int rows = 1;
  9.    int[][] matrix = new int[3][3];
  10.    matrix[1][1]=1;
  11.    
  12.    int TESTDELETE = 1;
  13.    while(rows!=0 /*&& columns<= 2*/ && number <= 9){
  14.        // System.out.print("Outermost while iteration is: " + TESTDELETE++ + " ");
  15.          if(count%2==0){
  16.             for(int i = count; i>0; i--){
  17.                
  18.                matrix[rows][columns-1]=++number;
  19.                --columns;
  20.             }
  21.             for(int i = count; i>0; i--){
  22.                matrix[rows-1][columns]=++number;
  23.                --rows;
  24.             }
  25.          }
  26.          if(count%2==1){
  27.             for(int i = count; i>0; i--){
  28.                
  29.                matrix[rows][columns+1]=++number;
  30.                ++columns;
  31.                //System.out.println("!@$!@#%@#$%" + matrix[rows][columns]);
  32.             }
  33.             for(int i = count; i>0; i--){
  34.                matrix[rows+1][columns] = ++number;
  35.                ++rows;
  36.             }
  37.            
  38.       }
  39.      
  40.       count++;
  41.       System.out.println("count is " + count);
  42.    }
  43.    
  44.    for(int i = 0; i < 3; i++){
  45.       for(int j = 0; j < 3; j++){
  46.          System.out.print(matrix[i][j]);
  47.       }
  48.       System.out.println();
  49.    }
  50.    }
  51. }
Add Comment
Please, Sign In to add comment