Results 1 to 3 of 3
- 04-04-2012, 07:37 PM #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.
- 04-04-2012, 07:39 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.
ANY CLUES? Thanks in advance
- 04-04-2012, 08:48 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Invocation of a Square
By jester-race in forum New To JavaReplies: 3Last Post: 02-04-2012, 08:39 AM -
Regular Expression issue and setName() method issue
By geforce in forum New To JavaReplies: 2Last Post: 01-30-2012, 03:33 AM -
Vending Machine Change - LOGIC Understanding ISSUE
By xcaldk74 in forum New To JavaReplies: 0Last Post: 01-25-2012, 07:54 PM -
Magic Square
By danthegreat in forum New To JavaReplies: 7Last Post: 10-06-2011, 01:53 AM -
How can I square(^2) the pic in the grid
By racewithferrari in forum New To JavaReplies: 2Last Post: 11-03-2009, 05:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks