Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class something
- {
- public static void main (String [] args)
- {
- int number = 1;
- int count = 0;
- int columns = 1;
- int rows = 1;
- int[][] matrix = new int[3][3];
- matrix[1][1]=1;
- int TESTDELETE = 1;
- while(rows!=0 /*&& columns<= 2*/ && number <= 9){
- // System.out.print("Outermost while iteration is: " + TESTDELETE++ + " ");
- if(count%2==0){
- for(int i = count; i>0; i--){
- matrix[rows][columns-1]=++number;
- --columns;
- }
- for(int i = count; i>0; i--){
- matrix[rows-1][columns]=++number;
- --rows;
- }
- }
- if(count%2==1){
- for(int i = count; i>0; i--){
- matrix[rows][columns+1]=++number;
- ++columns;
- //System.out.println("!@$!@#%@#$%" + matrix[rows][columns]);
- }
- for(int i = count; i>0; i--){
- matrix[rows+1][columns] = ++number;
- ++rows;
- }
- }
- count++;
- System.out.println("count is " + count);
- }
- for(int i = 0; i < 3; i++){
- for(int j = 0; j < 3; j++){
- System.out.print(matrix[i][j]);
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment