1 Attachment(s)
Please Help: Need Help with my Nested Loop
Im stuck on this loop Attachment 1537
I know what i got so far is wrong and no where close so can someone please help me
Code java:
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("..");
}
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.
Re: Please Help: Need Help with my Nested Loop
Quote:
Originally Posted by
helloworld922
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
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
||
__
_/\_
.............................................._/\_
.............................................._/\_
.............................................._/\_
.............................................._/\_
.............................................._/\_
.............................................._/\_
.............................................._/\_
.............................................._/\_
..............................................
Re: Please Help: Need Help with my Nested Loop
Quote:
Originally Posted by
hiroprotagonist
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
Code :
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;
}
}
}
}
}
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.
Re: Please Help: Need Help with my Nested Loop
Quote:
Originally Posted by
helloworld922
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
Code :
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("_");
}
}
}