Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
  1. #21
    luke is offline Member
    Join Date
    Sep 2010
    Posts
    62
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    It's all about generating equations from patterns. If we linearize the data by making it a straight line without a "reflection" like so:

    Java Code:
    x		y	
    ===================
    0		4		
    1		3		
    2		2		
    3		1		
    4		0		
    5		-1		
    6		-2		
    7		-3		
    8		-4
    We see that this is the plot of a line with slope -1 that intersects the y axis at 4 which mathematically means:

    y = -x + 4

    To make all negatives positive, I must take the absolute value of the right side:

    y = |4 - x|

    Substituting i for x and spaceMax for y and using the Java Math method for obtaining absolute value gives:

    Java Code:
    spaceMax = Math.abs(C - i);
    Where C is a constant that here = 4.

    Now when we play around with different values of MAX and check to see how this affects C we get:
    Java Code:
    MAX		C	
    ===================
    3		1		
    5		2		
    7		3		
    9		4		
    11		5		
    13		6
    we see that C = ((MAX - 1) / 2.0)
    but since int division tosses out any remainder, in Java, C is nothing more than MAX / 2

    Thanks for the great explanation, Fubarable.

    Why have you decided to substitute y with spaceMax (not with starMax):
    Java Code:
    spaceMax = Math.abs(C - i);

    I am not sure I understand the last section:
    Now when we play around with different values of MAX and check to see how this affects C we get:
    Java Code:
    MAX        C    
    ===================
    3        1        
    5        2        
    7        3        
    9        4        
    11      5        
    13      6
    we see that C = ((MAX - 1) / 2.0)
    but since int division tosses out any remainder, in Java, C is nothing more than MAX / 2
    You are playing with different values of spaceMax?
    Last edited by luke; 10-18-2010 at 08:04 PM.

  2. #22
    luke is offline Member
    Join Date
    Sep 2010
    Posts
    62
    Rep Power
    0

    Default

    Just lifting up my post. I hope you would have a couple of minutes for my questions.

  3. #23
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by luke View Post
    Thanks for the great explanation, Fubarable.

    Why have you decided to substitute y with spaceMax (not with starMax):
    Java Code:
    spaceMax = Math.abs(C - i);
    Because the data points most closely resembled the spaces data in a post earlier in this thread but without the "reflection" at the origin.


    I am not sure I understand the last section:

    You are playing with different values of spaceMax?
    I was playing with different values for all variables, and especially for MAX.

  4. #24
    luke is offline Member
    Join Date
    Sep 2010
    Posts
    62
    Rep Power
    0

    Default

    Thanks again for your reply, Fubarable.
    Following all your advice I tried to display a triangle this time. After spending some hours trying to figure out which of my formulas to use and for what I eventually made it.

    Java Code:
    static void printTriangle() {
    		
    		final int MAX = 7;
    		
    		for(int i = 0; i <= (MAX - 1) / 2; i++) {
    			
    			int space = MAX / 2 - i;
    			for( int j = 0; j < spaces; j++)
    				System.out.print(' ');
    			
    			for ( int k = 0; k < MAX - 2 * spaces ; k++)
    				System.out.print('*');
    			
    			System.out.println();
    			
    		}

    If you look into my code to see how I solved this problem do you think I've understood what you've explained to me or it could have been done in a better (more flexible) way?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Nested Loops Study Help Needed
    By gysnewbie in forum New To Java
    Replies: 5
    Last Post: 07-12-2010, 09:14 AM
  2. Nested Loops for Java
    By soccer_kid_6 in forum New To Java
    Replies: 4
    Last Post: 02-21-2010, 06:27 AM
  3. nested for loops
    By Implode in forum New To Java
    Replies: 4
    Last Post: 09-01-2009, 09:47 AM
  4. Nested Loops
    By ks1615 in forum New To Java
    Replies: 4
    Last Post: 02-18-2009, 03:48 AM
  5. Nested loops?
    By gabriel in forum New To Java
    Replies: 4
    Last Post: 08-06-2007, 05:51 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
  •