public static void main(String[] args) {
		
		
		int l=0;int r = 5;int u = 1;int d = 5;
		int n=0;
		int[][] arr = {{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5}};
		int i=0,j=0;
		int m = 1;
		int num = r*d;
		while (n< num){
			n++;
			switch(m){
			case 1:
				if(j<r-1){
					System.out.println(arr[i][j++]);
				}
				else{
					System.out.println(arr[i++][j]);
					r--;
					m=2;
				}
			break;
			
			case 2:
				if(i<d-1){
					System.out.println(arr[i++][j]);
				}
				else{
					System.out.println(arr[i][j--]);
					d--;
					m=3;
				}
			break;
			
			case 3:
				if(j>l){
					System.out.println(arr[i][j--]);
				}
				else{
					System.out.println(arr[i--][j]);
					l++;
					m=4;
				}
			break;
			
			case 4:
				if(i>u){
					System.out.println(arr[i--][j]);
				}
				else{
					System.out.println(arr[i][j++]);
					u++;
					m=1;
				}
			break;
			}

		}

	}