Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Please Help: Need Help with my Nested Loop

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please Help: Need Help with my Nested Loop

    Im stuck on this loop Scan 3.jpg
    I know what i got so far is wrong and no where close so can someone please help me
    public class LincolnField {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    	for(int i = 0; i <= 20; i++)
    	{
    		System.out.print("|");
    		/*for(int j= 1; j <= 36; j++)
    		{
    			System.out.print("_");
    		}*/
    		System.out.println("|");
    	}
     
     
    	System.out.println("__");
    	for(int i = 1; i <= 9; i++)
    	{
    		System.out.println("_/" + "\\_");
    		for(int j = 0; j <= 22; j++)
    		{
     
    			System.out.print("..");
    		}
    Last edited by helloworld922; November 18th, 2012 at 06:36 PM. Reason: please use [code] tags


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Please Help: Need Help with my Nested Loop

    What is the compiler telling you? What results are you getting when you try to run the program?

    I can see you have some missing curly braces at the end of your code. This is possibly a copy/paste error, though I can't tell without knowing what the compiler is telling you.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help: Need Help with my Nested Loop

    Quote Originally Posted by helloworld922 View Post
    What is the compiler telling you? What results are you getting when you try to run the program?

    I can see you have some missing curly braces at the end of your code. This is possibly a copy/paste error, though I can't tell without knowing what the compiler is telling you.
    the compiler is telling me this
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    __
    _/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    ..............................................

  4. #4
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help: Need Help with my Nested Loop

    Quote Originally Posted by hiroprotagonist View Post
    the compiler is telling me this
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    ||
    __
    _/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    .............................................._/\_
    ..............................................
    i updated my code but im still having problems with my second method and the math that comes with it
    public class LincolnField1 {
     
    private String dots =".";
    private String frontDashes = "_/";
    private String lastDashes = "\\_";
    private String topLines ="_";
    private String sideLines = "|";
    private String stars ="********";
     
    private String linePrinter = "";
     
    public int field()
    {
    	for(int i = 0; i <= 20; i++)
    	{
    	 linePrinter = sideLines + drawline(i) + sideLines;
     
    	}
    }
     
    public void drawline(int length)
    {
    	for(int i = 0; i<= 36; i++)
    	{
    		if(length > 2)
    		{
    			if(length > 14)
    			{
    				dots = dots + stars;
    			}
    		}
    	}
     
    }
     
     
    }

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Please Help: Need Help with my Nested Loop

    I can't clearly make out what the assignment is based off of the image you posted, but it looks like you're missing all the spaces.

  6. #6
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help: Need Help with my Nested Loop

    Quote Originally Posted by helloworld922 View Post
    I can't clearly make out what the assignment is based off of the image you posted, but it looks like you're missing all the spaces.
    I changed by my code im having problems with including the stars into the code, it prints everything else
    public class LicolnField2 {
     
    	private static final String dot = ".";
    	private static final String frontDashes = "_/";
    	private static final String lastDashes = "\\_";
    	private static final String topLines = "_";
    	private static final String sideLines = "|";
    	private static final String stars = "********";
    	private static final String space = " ";
     
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    		// print top line
    		for(int j = 0; j < 36; j++)
    		{
    			System.out.print("_");
    		}
    		System.out.println("");
     
    		// loop for expanding triangle
    		for(int row = 1; row < 9; row++)
    		{
    			int firstRowDots = 2;
    			int numDots = 4*row - firstRowDots;
    			int numSpaces =( 36 - (numDots + 4))/2;
    			System.out.print(sideLines);
    			for (int i = 0; i < numSpaces; i++) {
    				System.out.print(space);
    			}
    			System.out.print(frontDashes);
    			for (int i = 0; i < numDots; i++) {
    				System.out.print(dot);
    			}
    			System.out.print(lastDashes);
    			for (int i = 0; i < numSpaces; i++) {
    				System.out.print(space);
     
    			}
    			System.out.print(sideLines);
    			System.out.println("");
    		}
     
    		// loop for shrinking triangle
    		for(int row = 0; row < 8; row++)
    		{
    			int firstRowDots = 28;
    			int numDots = -4*row + firstRowDots ;
    			int numSpaces =( 36 - (numDots + 4))/2;
    			System.out.print(sideLines);
    			for (int i = 0; i < numSpaces; i++) {
    				System.out.print(space);
    			}
    			System.out.print(lastDashes);
    			for (int i = 0; i < numDots; i++) {
    				System.out.print(dot);
    			}
    			System.out.print(frontDashes);
    			for (int i = 0; i < numSpaces; i++) {
    				System.out.print(space);
     
    			}
    			System.out.print(sideLines);
    			System.out.println("");
    		}
    		//Print bottom line
    		for(int j = 0; j < 36; j++)
    		{
    			System.out.print("_");
    		}
     
     
    	}
     
    }

Similar Threads

  1. Nested For Loop!
    By samadniz in forum Object Oriented Programming
    Replies: 3
    Last Post: September 3rd, 2012, 04:03 PM
  2. Help me out with this nested for loop plz..
    By samadniz in forum Loops & Control Statements
    Replies: 3
    Last Post: September 3rd, 2012, 10:00 AM
  3. Having some nested loop problem
    By joel1314 in forum Loops & Control Statements
    Replies: 13
    Last Post: June 3rd, 2012, 05:04 AM
  4. Nested for loop
    By wolf_fcknHaley33 in forum Loops & Control Statements
    Replies: 2
    Last Post: May 23rd, 2012, 08:49 AM
  5. nested loop
    By b109 in forum Java Theory & Questions
    Replies: 1
    Last Post: May 30th, 2010, 10:05 AM