Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33
  1. #21
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    yea I formatted it as you did and the only thing I could think of to try as to move the i increment into the outer loop
    Last edited by jjth39347; 04-01-2011 at 01:27 AM. Reason: spelling

  2. #22
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Thats heading in the right direction. Ill give you something to work with.

    Java Code:
    declare i
    declare j
    
    while i < x
      while j < y
        print char 
        //increment? which variable(s)?
      end inner while
      print a line
    end outer while
    I left some problems, see if you can decide whats wrong. Give it a try, if you still cant get it I will post a close to working program with some bugs that Ill let you figure out.

  3. #23
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    I keep ending up around here trying to figure it out

    Java Code:
    	public static int printLines(int noLines, int charPerLine, char theChar)  // my method.
    	{
    	    int i=0;
    	    int j=0;// variables for loops
    	    while (i < noLines) // loop for number of lines
    	    {
    			System.out.println("");
    			while (j < charPerLine) // loop for characters per line
    			{
    				System.out.print(""+theChar);
    				j++;
    			}
    i++;
    			// end output line
    		}
    	    return noLines * charPerLine; // show your method my methods results.
    	}
    I've moved all the print out statements all over the place, tried incrementing in different place, still can't get it right.

  4. #24
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    This looks good, what output does it give you?

  5. #25
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    Java Code:
    How many lines you want?  4
    How many characters per line?  4
    What character?    +
    
    ++++
    
    
    main reports 16  characters printed
    Do another?(y/n)

  6. #26
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Try adding some print statements to print the values of i and j. After the first loop, what will the value of each be?

  7. #27
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    did that and still can't figure out what the hell I'm doing wrong, I think I've just been working to hard today (not on this I'm a website developer) but here is the output of when I added print i and j statements

    Java Code:
    How many lines you want?  4
    How many characters per line?  4
    What character?    +
    0
    01231
    2
    3
    main reports 16  characters printed
    Do another?(y/n)

  8. #28
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Try printing j in three spots, before the inner loop, in the inner loop and after the inner loop. Also, have a line that prints where the value is
    Java Code:
    System.out.println("this is before the loop " + j);
    this should hopefully help you solve the problem. It's something small and you may kick yourself when you catch it. It took me a minute or two to realize it.

  9. #29
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    okay I'm just not getting it, I've tried everything you've suggested but nada.

  10. #30
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    J gets incremented x times in the inner loop and it prints x symbols. The problem is that after the first cycle of the inner loop j is x, after the second time through the outer loop j is still x. Because of this is won't re enter the inner loop. What can you do to j to allow it to enter the inner loop?

  11. #31
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    hmm
    j=0
    before the inner loop?

  12. #32
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    yea I'm kicking my-self as I type

  13. #33
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Haha ya I know, I couldn't believe I missed something so small as well.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. is it possible to do this to methods?
    By alacn in forum New To Java
    Replies: 8
    Last Post: 08-14-2010, 03:01 PM
  3. methods
    By blueduiker in forum New To Java
    Replies: 12
    Last Post: 02-09-2010, 03:50 PM
  4. Replies: 4
    Last Post: 04-03-2009, 06:36 AM
  5. Get and Set Methods
    By kian_hong2000 in forum New To Java
    Replies: 10
    Last Post: 08-27-2008, 02:06 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
  •