Checkerboard with nested for statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcollins1989
    New Member
    • Feb 2008
    • 3

    Checkerboard with nested for statements

    Draw a checkerboard (8 by 8 squares) out of vertical lines and underscores. You must use two nested for loops, and the for loops should each execute 8 times, e.g.

    for (int x = 0; x < 8; x++)
    {
    for (int y = 0; y < 8; y++)
    {
    // print out one square of the checkerboard
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Yes, and your question is?

    kind regards,

    Jos

    Comment

    • mcollins1989
      New Member
      • Feb 2008
      • 3

      #3
      I cant exactly get the boxes right.
      I keep getting
      _ _ _ _ _ _ _ _
      |_||_||_||_||_| |_||_||_| _ _ _ _ _ _ _ _
      |_||_||_||_||_| |_||_||_| _ _ _ _ _ _ _ _
      |_||_||_||_||_| |_||_||_| _ _ _ _ _ _ _ _
      |_||_||_||_||_| |_||_||_| _ _ _ _ _ _ _ _
      |_||_||_||_||_| |_||_||_| _ _ _ _ _ _ _ _
      |_||_||_||_||_| |_||_||_| _ _ _ _ _ _ _ _
      |_||_||_||_||_| |_||_||_| _ _ _ _ _ _ _ _
      |_||_||_||_||_| |_||_||_|


      Here is my code now
      public class W7E1
      {

      public static void main(String[] args)
      {

      for (int x = 0; x < 8; x++)
      {
      System.out.prin tln(" _ _ _ _ _ _ _ _");
      for (int y = 0; y < 8; y++)
      {
      System.out.prin t("|_|");


      }

      }
      }

      }

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Skill testing question: what is the difference between print() and println()?

        Comment

        • mcollins1989
          New Member
          • Feb 2008
          • 3

          #5
          im pretty sure println prints a new line, and print prints on the current line.

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            Originally posted by mcollins1989
            im pretty sure println prints a new line, and print prints on the current line.
            Close. println append a newline onto the end of its output and print doesn't. Hmmm...

            Comment

            • nomad
              Recognized Expert Contributor
              • Mar 2007
              • 664

              #7
              Originally posted by BigDaddyLH
              Close. println append a newline onto the end of its output and print doesn't. Hmmm...

              read BigDaddy clue he gives it away.

              nomad

              Comment

              • BigDaddyLH
                Recognized Expert Top Contributor
                • Dec 2007
                • 1216

                #8
                Originally posted by nomad
                read BigDaddy clue he gives it away.

                nomad
                Clue: whenever I write "Hmmm...", I've just given something away. Hmmm...

                Comment

                Working...