0

For my class we need to create an Ascii drawing with at least 3 nested loops and 3 different type of loops. this is what i have so far ( just 2 lines of the drawing)

for(int i = 0; i<=4; i++)
    {
        System.out.print("0");
    }
    for(int i = 0; i<=13; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=4; i++)
    {
        System.out.print("0");
    }
    for(int i = 0; i<=10; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=16; i++)
    {
        System.out.print("8");
    }
    for(int i = 0; i<=2; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=13; i++)
    {
        System.out.print("p");
    }

How exactly can I make this either shorter or have a nested loop or a different type of loop?

1
Contributor
1
Reply
4
Views
5 Years
Discussion Span
Last Post by Seswing142
1

It didnt paste everything so this is the updated version!

public class AsciiArt 
{
    public static void main(String[] args)
    {
        System.out.print("  ");
    for(int i = 0; i<=4; i++)
    {
        System.out.print("0");
    }
    for(int i = 0; i<=13; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=4; i++)
    {
        System.out.print("0");
    }
    for(int i = 0; i<=10; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=16; i++)
    {
        System.out.print("8");
    }
    for(int i = 0; i<=2; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=13; i++)
    {
        System.out.print("p");
    }



    //second line
    System.out.print("\n");
    for(int i = 0; i<=8; i++)
    {
        System.out.print("0");
    }
    for(int i = 0; i<=9; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=8; i++)
    {
        System.out.print("0");
    }
    for(int i = 0; i<=8; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=15; i++)
    {
        System.out.print("8");
    }
    for(int i = 0; i<=2; i++)
    {
        System.out.print("|");
    }
    for(int i = 0; i<=14; i++)
    {
        System.out.print("p");
    }
}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.