What's new

Closed Java programmers pasok

Status
Not open for further replies.

PHC-MJ

Forum Veteran
Joined
Apr 9, 2016
Posts
1,649
Solutions
143
Reaction
1,463
Points
809
Create a for loop, do while loop and while loop for each item that will display the output below;

Assignment.png



Baka naman po may maiambag po jayo sobrang dami kasi naiiyak na ko dito sa assignment ko

Code:
public class HelloWorld{

     public static void main(String []args){
 
       int jayson, cielo;

   System.out.print("---------------------------------------------");
 
   System.out.print("\nNumber 1");
   System.out.print("\n\t\tFOR LOOP\n");
        for(jayson=1; jayson<=5; jayson++){
      System.out.print("\t\t ");
             for(cielo=1; cielo<=5; cielo++) {
        System.out.print("* ");
        }
        System.out.print("\n");
    }

    System.out.print("\n\t\tDO WHILE LOOP");
    jayson=1;
      do{
          jayson++;
          cielo=1;
      System.out.print("\n\t\t ");
          do{
          System.out.print("* ");
              cielo++;
          }
          while(cielo<=5);
      }
      while(jayson<=5);

    System.out.print("\n\n\t\tWHILE LOOP");
      jayson=1;
      while(jayson<=5){
          System.out.print("\n\t\t ");
          jayson++;
          cielo=1;
          while(cielo<=5){
          System.out.print("* ");
              cielo++;
          }
      }

    System.out.print("\n");
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 2");
  System.out.print("\n\t\tFOR LOOP\n");
 
  System.out.println("\n\t\tDO WHILE LOOP");
  int cielo1=0,jayson1;
    do 
    {
        jayson1=1;
                 while(jayson1<=5) // Width to **** ko talaga
        {
            System.out.print(jayson1); 
            jayson1++;
        }
        System.out.println();
                ++cielo1;
        }
         while(cielo1<5); //Height pala to tang na
      
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");

  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 3");
  System.out.print("\n\t\tFOR LOOP\n");
 for (int sonjay = 1; sonjay <= 5; sonjay++) {
 
 
            for (int locie = 5; locie >= sonjay; locie--) {
                System.out.print(" ");
            }
 

            for (int locie = 1; locie <= sonjay; locie++) {
                System.out.print("* ");
            }
 
            System.out.println();
        }
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
  System.out.print("---------------------------------------------");
   System.out.print("\nNumber 4");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");
 
  System.out.print("\n");
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 5");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 6");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 7");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 8");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 9");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 10");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
 
 }
}
 

Attachments

UPDATE KO YUNG CODE PA VIEW NANG NUMBER 5,6,9,10


Code:
package assignment;


public class Assignment {
                
    
    public static void main(String[] args) {
      

 
       int jayson, cielo;
        System.out.println("\t\t\t\tHappy New Year Sir Mac Delgado Pogi");


   System.out.print("---------------------------------------------");
  System.out.print("\nNumber 1");
   System.out.print("\n\t\tFOR LOOP\n");
        for(jayson=1; jayson<=5; jayson++){
      System.out.print("\t\t ");
             for(cielo=1; cielo<=5; cielo++)
        {
        System.out.print("* ");
        }
        System.out.print("\n");
    }

    System.out.print("\n\t\tDO WHILE LOOP");
    jayson=1;
      do{
          jayson++;
          cielo=1;
      System.out.print("\n\t\t ");
          do{
          System.out.print("* ");
              cielo++;
          }
          while(cielo<=5);
      }
      while(jayson<=5);

    System.out.print("\n\n\t\tWHILE LOOP");
      jayson=1;
      while(jayson<=5){
          System.out.print("\n\t\t ");
          jayson++;
          cielo=1;
          while(cielo<=5){
          System.out.print("* ");
              cielo++;
          }
      }

    System.out.print("\n");
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 2");
  System.out.print("\n\t\tFOR LOOP\n");
        
    for(jayson=1; jayson<=5; jayson++){
      System.out.print("\t\t ");
     for(cielo=1; cielo<=5; cielo++)
        {
        System.out.print(cielo+" ");
        }
        System.out.print("\n");
    }

  System.out.println("\n\t\tDO WHILE LOOP");
  int cielo1=0,jayson1;
    
        do   
    {
        jayson1=1; 
                 while(jayson1<=5) // Width to **** ko talaga
        {
            System.out.print(jayson1+" ");   
            jayson1++;
        }
        System.out.println( );
                ++cielo1;
        }
         while(cielo1<5); //Height pala to tang na
        
  System.out.print("\n\n\t\tWHILE LOOP");

  jayson=1;
      while(jayson<=5){
          System.out.print("\n ");
          jayson++;
          cielo=1;
          while(cielo<=5){
          System.out.print(cielo+" ");
              cielo++;
          }
      }

 

    

  System.out.print("\n");

  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 3");
  System.out.print("\n\t\tFOR LOOP\n");
 for (int sonjay = 1; sonjay <= 5; sonjay++) {
 
 
            for (int locie =5; locie >= sonjay; locie--) {
                System.out.print(" ");
            }
 

            for (int locie = 1; locie <= sonjay; locie++) {
                System.out.print("* ");
            }
 
            System.out.println();
        }
 
  System.out.println("\n\t\tDO WHILE LOOP");
 
              
int JAYSON143=1;
                    do {
                      JAYSON143++;
                        int CIELO01=5;
                         int MJJ=2;
                           System.out.print("\n");
                         do{
                            CIELO01--;
                            System.out.print(" ");
                        }while(CIELO01>=JAYSON143);
                        
                            do{
                              MJJ++;
                              
                               System.out.print("* ");
                                
                           }while(MJJ<=JAYSON143);
                         }while(JAYSON143 <=5);
  }
}
 
 
  System.out.print("\n\n\t\tWHILE LOOP");


  int JAYSONSKIE=1;
                      while( JAYSONSKIE <=5){
                        System.out.print("\n");
                        JAYSONSKIE++;
                          int CIELOSKIE=5;
                          int MJSKIE=2;
                          while(CIELOSKIE >=JAYSONSKIE){
                            System.out.print(" ");
                            CIELOSKIE--;
                             }
                             while(MJSKIE<=JAYSONSKIE){
                              System.out.print("* ");
                              MJSKIE++;
                             }
                      }




  System.out.print("\n");
 
  System.out.print("---------------------------------------------");
   System.out.print("\nNumber 4");
  System.out.print("\n\t\tFOR LOOP\n");
  for (int sonjay = 1; sonjay <= 5; sonjay++) {
 
 
            for (int locie =5; locie >= sonjay; locie--) {
                System.out.print(" ");
            }
 

            for (int locie = 1; locie <= sonjay; locie++) {
                System.out.print(sonjay+" ");
            }
 
            System.out.println();
        }
  System.out.print("\n\t\tDO WHILE LOOP");

              int JAYSON122=0;
                do{
                  JAYSON122++;
                  int CIELO122=5,JM122=1;
                   System.out.print("\n");
                  do{
                    CIELO122--;
                    System.out.print(" ");
                  }while(CIELO122>=JAYSON122);
                  do{
                    System.out.print(JAYSON122+" ");
                    JM122++;
                  }while(JM122<=JAYSON122);
                  }while(JAYSON122<=4);
                System.out.println();



            
 
  System.out.print("\n\n\t\tWHILE LOOP");

      int MACPOGI=0;
                  while(MACPOGI<=4){
                    MACPOGI++;
                    int MACPOGI123=5,CIELOPOGI=1;
                    System.out.println();
                      while(MACPOGI123>=MACPOGI){
                        MACPOGI123--;
                        System.out.print(" ");
                      }
                        while(CIELOPOGI<=MACPOGI){
                          CIELOPOGI++;
                          System.out.print(MACPOGI+" ");

                        }
                  }





 
  System.out.print("\n");
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 5");
  System.out.print("\n\t\tFOR LOOP\n");
 
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 6");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 7");
    System.out.print("\n\t\tFOR LOOP\n");
int akojayson = 5;
  for(int siakojayson=akojayson;siakojayson>=1;siakojayson--)
  {
      for(int siakocielo =akojayson -1;siakocielo>=siakojayson;siakocielo--)
      {
          System.out.print(" ");
      }
      for(int akocielo=siakojayson;akocielo>=1;akocielo--)
      {
               System.out.print("* ");
      }
      System.out.print("\n");
  }   
   System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 8");
  System.out.print("\n\t\tFOR LOOP\n");
  int jaysonh = 5;
  for(int icielo=jaysonh;icielo>=1;icielo--)
  {
      for(int mj =jaysonh -1;mj>=icielo;mj--)
      {
          System.out.print(" ");
      }
      for(int jm=icielo;jm>=1;jm--)
      {
               System.out.print(icielo+" ");
      }
      System.out.print("\n");
  }
 
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 9");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
  System.out.print("---------------------------------------------");
  System.out.print("\nNumber 10");
  System.out.print("\n\t\tFOR LOOP\n");
  System.out.print("\n\t\tDO WHILE LOOP");
  System.out.print("\n\n\t\tWHILE LOOP");

  System.out.print("\n");
 
 
 }
}

}
    
}
 
Don't put everything in one main function as one main loop. If you understand that, you are on your way to being a better programmer.

Programming is not just about typing characters and writing programming logic. It's also about making sure the code is clean, maintainable, and readable.
 
For those still wondering a possible solution to the given problems, here's my initial take on these. I am sure things can be simplified further.

What we want to do first:
  • Identify common patterns. This will allow us to see if there are reusable logic.
  • Identify common methods. This will allow us to consolidate methods and have less noise in the implementation.
  • Separate "textual art" from logic. This will allow us to provide custom "textual art"
We can visualize each "art" above as an independent objects with print as a common denominator.

First, let's declare an interface: AsciiArt
Code:
interface AsciiArt {
    void print();
    void print(String[] pattern);
}
All of our "art" implementations will implement this interface. This means everyone will have two types of print methods: one that uses the given "characters" from the problem and another method where we can pass custom characters.


Let's implement our "Rectangle art":
Code:
class RectangleArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 5;

    private RectangleArt() {}

    public static RectangleArt of() {
        return new RectangleArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                System.out.print(pattern[col]);
                System.out.print(WHITESPACE);
            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{ASTERISK, ASTERISK, ASTERISK, ASTERISK, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }

}
If you look at this RectangleArt class, we have implemented two print methods because our interface has two print methods.

Let's run this RectangleArt
Code:
public class App {

    public static void main(String[] args) {
        RectangleArt.of().print();
        RectangleArt.of().print(new String[]{"1","2","3","4","5"});
        RectangleArt.of().print(new String[]{"z","z","z","z","z"});
        RectangleArt.of().print(new String[]{"z","z","z","y","y"});
    }
}

Here's the output:
Code:
* * * * * 
* * * * * 
* * * * * 
* * * * * 
* * * * * 

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 

z z z z z 
z z z z z 
z z z z z 
z z z z z 
z z z z z 

z z z y y 
z z z y y 
z z z y y 
z z z y y 
z z z y y
Notice how we're able to pass custom character sets.
 
Now let's implement the Pyramid Art. We will follow the same workflow:

Here's the PyramidArt class
Code:
class PyramidArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 9;

    private PyramidArt() {}

    public static PyramidArt of() {
        return new PyramidArt();
    }

    private void process(String[] pattern) {
        int mid = COLS/2;

        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                int stopper = mid - row;

                if (col < stopper) {
                    System.out.print(WHITESPACE);
                } else if (col == stopper) {
                    for (int i = 0; i < row + 1; i++) {
                        System.out.print(pattern[row]);
                        System.out.print(WHITESPACE);
                    }
                } else if (col > stopper) {
                    System.out.print(WHITESPACE);
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{ASTERISK, ASTERISK, ASTERISK, ASTERISK, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }

}
Same interface with a slight difference in implementation.

Let's run this PyramidArt:
Code:
public class App {

    public static void main(String[] args) {
        PyramidArt.of().print();
        PyramidArt.of().print(new String[]{"1","2","3","4","5"});
        PyramidArt.of().print(new String[]{"8","8","8","4","5"});
    }
}

Here's the output:
Code:
    *     
   * *      
  * * *       
 * * * *        
* * * * *         

    1     
   2 2      
  3 3 3       
 4 4 4 4        
5 5 5 5 5         

    8     
   8 8      
  8 8 8       
 4 4 4 4        
5 5 5 5 5
 
You should see the workflow now. The reason why it's hard to comprehend and reason out on the poster's solution is because the code was written poorly.

The solution wasn't decomposed in a manner that's easily understandable and maintainable. Simplify, simplify, simplify!
 
Now let me give you the rest of the solutions. Follow the same pattern:

Code:
class InvertedPyramidArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 9;

    private InvertedPyramidArt() {}

    public static InvertedPyramidArt of() {
        return new InvertedPyramidArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                int stopper = row;

                if (col < stopper) {
                    System.out.print(WHITESPACE);
                } else if (col == stopper) {
                    for (int i = ROWS-row; i > 0; i--) {
                        System.out.print(pattern[row]);
                        System.out.print(WHITESPACE);
                    }
                } else if (col > stopper) {
                    System.out.print(WHITESPACE);
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{ASTERISK, ASTERISK, ASTERISK, ASTERISK, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }

}


class DiagonalArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String PLUS = "+";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 5;

    private DiagonalArt() {}

    public static DiagonalArt of() {
        return new DiagonalArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                int stopper = row;

                if (col < stopper) {
                    System.out.print(pattern[0]);
                    System.out.print(WHITESPACE);
                } else {
                    System.out.print(pattern[1]);
                    System.out.print(WHITESPACE);
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{PLUS, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }

}



class InvertedDiagonalArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String PLUS = "+";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 5;

    private InvertedDiagonalArt() {}

    public static InvertedDiagonalArt of() {
        return new InvertedDiagonalArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                int stopper = COLS - (row + 1);

                if (col < stopper) {
                    System.out.print(pattern[0]);
                    System.out.print(WHITESPACE);
                } else {
                    System.out.print(pattern[1]);
                    System.out.print(WHITESPACE);
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{PLUS, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }

}



class ComplexArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String PLUS = "+";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 9;

    private ComplexArt() {}

    public static ComplexArt of() {
        return new ComplexArt();
    }

    private void process(String[] pattern) {
        int mid = COLS/2;

        for (int row = 0; row < ROWS; row++) {

            int k = 0;
            int j = ROWS-1;
            for (int col = 0; col < COLS; col++) {
                int stopper = mid - row;

                if (col < stopper) {
                    // Render initial 50% of outer
                    System.out.print(pattern[0]);
                    System.out.print(WHITESPACE);
                } else if (col == stopper) {
                    // Render initial 50% of inner
                    for (int i = 0; i < row + 1; i++) {
                        System.out.print(pattern[1]);
                        System.out.print(WHITESPACE);
                    }
                } else if (col > stopper) {
                    // Render remaining 50% of inner
                    for (; k < row; k++) {
                        System.out.print(pattern[1]);
                        System.out.print(WHITESPACE);
                    }
                    // Render remaining 50% of outer
                    for (; j > row; j--) {
                        System.out.print(pattern[0]);
                        System.out.print(WHITESPACE);
                    }
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{PLUS, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }
}


class InvertedComplexArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String PLUS = "+";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 9;

    private InvertedComplexArt() {}

    public static InvertedComplexArt of() {
        return new InvertedComplexArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {

            int k = 0;
            int j = 0;
            for (int col = 0; col < COLS; col++) {
                int stopper = row;

                if (col < stopper) {
                    // Render initial 50% of outer
                    System.out.print(pattern[0]);
                    System.out.print(WHITESPACE);
                } else if (col == stopper) {
                    // Render initial 50% of inner
                    for (int i = ROWS-row; i > 0; i--) {
                        System.out.print(pattern[1]);
                        System.out.print(WHITESPACE);
                    }
                } else if (col > stopper) {
                    // Render remaining 50% of inner
                    for (; k < ROWS-row-1; k++) {
                        System.out.print(pattern[1]);
                        System.out.print(WHITESPACE);
                    }
                    // Render remaining 50% of outer
                    for (; j < row; j++) {
                        System.out.print(pattern[0]);
                        System.out.print(WHITESPACE);
                    }
                }

            }

            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{PLUS, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }
}

When you run these, you should see these output:
Code:
* * * * *         
 * * * *        
  * * *       
   * *      
    *     

5 5 5 5 5         
 4 4 4 4        
  3 3 3       
   2 2      
    1     

8 8 8 8 8         
 8 8 8 8        
  8 8 8       
   4 4      
    5     

* * * * * 
+ * * * * 
+ + * * * 
+ + + * * 
+ + + + * 

y y y y y 
x y y y y 
x x y y y 
x x x y y 
x x x x y 

4 4 4 4 4 
5 4 4 4 4 
5 5 4 4 4 
5 5 5 4 4 
5 5 5 5 4 

+ + + + * 
+ + + * * 
+ + * * * 
+ * * * * 
* * * * * 

x x x x y 
x x x y y 
x x y y y 
x y y y y 
y y y y y 

5 5 5 5 4 
5 5 5 4 4 
5 5 4 4 4 
5 4 4 4 4 
4 4 4 4 4 

+ + + + * + + + + 
+ + + * * * + + + 
+ + * * * * * + + 
+ * * * * * * * + 
* * * * * * * * * 

x x x x y x x x x 
x x x y y y x x x 
x x y y y y y x x 
x y y y y y y y x 
y y y y y y y y y 

5 5 5 5 4 5 5 5 5 
5 5 5 4 4 4 5 5 5 
5 5 4 4 4 4 4 5 5 
5 4 4 4 4 4 4 4 5 
4 4 4 4 4 4 4 4 4 

* * * * * * * * * 
+ * * * * * * * + 
+ + * * * * * + + 
+ + + * * * + + + 
+ + + + * + + + + 

y y y y y y y y y 
x y y y y y y y x 
x x y y y y y x x 
x x x y y y x x x 
x x x x y x x x x 

4 4 4 4 4 4 4 4 4 
5 4 4 4 4 4 4 4 5 
5 5 4 4 4 4 4 5 5 
5 5 5 4 4 4 5 5 5 
5 5 5 5 4 5 5 5 5

Again you should see how complex problems can be tackled in a manageable manner if you approach it a systematic way.
 
Now what do I want further from my solution. I want those loops to be refactored in a way that there's less loops or probably consolidate them with the other loops. Also I want to be able to pass custom rows and cols. Add some validation too.
 
I have my separate thread of this topic written in C#. everything is already there. you just have to translate it to Java which is an almost the same language.
 
Status
Not open for further replies.

Similar threads

Back
Top