| 24 | * forms a word (reading top to bottom) from the list. |
| 25 | */ |
| 26 | public Rectangle maxRectangle() { |
| 27 | // The dimensions of the largest possible rectangle. |
| 28 | int maxSize = maxWordLength * maxWordLength; |
| 29 | |
| 30 | for (int z = maxSize; z > 0; z--) { |
| 31 | // Find out all pairs i,j less than maxWordLength |
| 32 | // such that i * j = z |
| 33 | for (int i = 1; i <= maxWordLength; i ++ ) { |
| 34 | if (z % i == 0) { |
| 35 | int j = z / i; |
| 36 | if (j <= maxWordLength) { |
| 37 | // Check if a Rectangle of length i and height |
| 38 | // j can be created. |
| 39 | Rectangle rectangle = makeRectangle(i,j); |
| 40 | if (rectangle != null) { |
| 41 | return rectangle; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | /* This function takes the length and height of a rectangle as |
| 51 | * arguments. It tries to form a rectangle of the given length and |