Results 1 to 3 of 3
  1. #1
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Question 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. #2
    xcaldk74 is offline Member
    Join Date
    Jan 2012
    Posts
    40
    Rep Power
    0

    Default 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

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default Re: Hollow square n x n logic issue - help!

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

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Vending Machine Change - LOGIC Understanding ISSUE
    By xcaldk74 in forum New To Java
    Replies: 4
    Last Post: 01-24-2014, 03:10 PM
  2. Invocation of a Square
    By jester-race in forum New To Java
    Replies: 3
    Last Post: 02-04-2012, 08:39 AM
  3. Regular Expression issue and setName() method issue
    By geforce in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 03:33 AM
  4. Magic Square
    By danthegreat in forum New To Java
    Replies: 7
    Last Post: 10-06-2011, 01:53 AM
  5. How can I square(^2) the pic in the grid
    By racewithferrari in forum New To Java
    Replies: 2
    Last Post: 11-03-2009, 05:27 PM

Posting Permissions

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