Thread: Hollow square n x n logic issue - help!

1. Member
Join Date
Jan 2012
Posts
40
Rep Power
0

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:

Java 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("");
}
}
}```
Last edited by xcaldk74; 04-04-2012 at 07:40 PM.

2. Member
Join Date
Jan 2012
Posts
40
Rep Power
0

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.

3. Re: Hollow square n x n logic issue - help!

Originally Posted by xcaldk74
Which doesn't make sense since my logic should work.
(row*col)/col == row, always.

kind regards,

Jos

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•