Advertisement
brilliant_moves

NestedForLoops.java

Jan 20th, 2020
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.89 KB | None | 0 0
  1.     public static void main (String[] args) {
  2.         // declare integer variables
  3.         int i, r, c;
  4.  
  5.         // print horizontal line at top
  6.         System.out.print ("+"); // corner
  7.         for (c=0; c<6; c++) {
  8.             System.out.print ("-");
  9.         }// for c
  10.         System.out.println ("+"); // corner and new line
  11.  
  12.         // outer loop
  13.         for (i=0; i<2; i++) {
  14.             // inner loop
  15.             for (r=0; r<6; r++) {
  16.                 System.out.print ("|"); // vertical line
  17.                 if (r%3==0) {
  18.                     System.out.print ("  ^^  ");
  19.                 } else if (r%3==1) {
  20.                     System.out.print (" ^  ^ ");
  21.                 } else {
  22.                     System.out.print ("^    ^");                   
  23.                 }// if
  24.                 System.out.println ("|"); // vertical line and new line
  25.             } // end inner loop
  26.  
  27.             // print horizontal line
  28.             System.out.print ("+"); // corner
  29.             for (c=0; c<6; c++) {
  30.                 System.out.print ("-");
  31.             }// for c
  32.             System.out.println ("+"); // corner and new line
  33.         } // end outer loop
  34.     } // main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement