# Hollow square n x n logic issue - help!

• 04-04-2012, 07:37 PM
xcaldk74
Hollow square n x n logic issue - help!
Hi Java Masters,

I'm to print hollow square where user will enter positive integer from which square will be made n x n.(see below)

CORRECT OUTPUT:

user enters ; 5

*****
* ...*
* ...*
* ...*
***** <--in this example 5x5, picture not perfect where the dots are should be empty space so you only get the borders...

This is what I'm getting OUTPUT:

*....
.*...
..*..
...*.
....*

Which doesn't make sense since my logic should work. What is wrong with the equation? CODE BELOW:

Code:

```import java.util.Scanner; public class hw8a {         public static void main(String[] args)         {         Scanner kybd = new Scanner (System.in);                 int n;         int maxint = 21;         int row,col;         //int sq = row*col;                         System.out.print("Enter a positive odd integer: ");         n = kybd.nextInt();         System.out.println("");                 for(row = 1; row<=n; row++)         {                 for(col = 1; col<=n; col++)                 {                         if(((row*col)/col)==col)                         {                                 System.out.print("*");                         }                                                 else                                 System.out.print(".");                 }         System.out.println("");         }  } }```
• 04-04-2012, 07:39 PM
xcaldk74
Re: Hollow square n x n logic issue - help!
DOESN'T MAKE SENSE. I.E ROW =1, COL = 1 1X1 / 1 == 1 // TRUE SO SOP("*")
COL++;

ROW = 1, COL = 2 SO 1X2 / 2 == 1 // TRUE SO SOP SHOULD BE "*" NOT DOT.