/* NestedBrackets.java by Craig Persiko
Solution to in-class exercise 3 for loops in CS 111A:
Write nested loops that make a pattern of brackets
*/
import java.util.Scanner;
public class NestedBrackets
{
public static void main(String[] args)
{
Scanner scan = new Scanner (System.in);
int width, height;
System.out.print("This program outputs a shape. How wide do you want it? ");
width = scan.nextInt();
System.out.print("How tall? ");
height = scan.nextInt();
for(int i=1; i<=height; i++)
{
for(int j=1; j<=width; j++)
System.out.print("[]");
System.out.println();
}
}
}
/* Sample Output:
[cpersiko@fog cs111a]$ javac NestedBrackets.java
[cpersiko@fog cs111a]$ java NestedBrackets
This program outputs a shape. How wide do you want it? 4
How tall? 3
[][][][]
[][][][]
[][][][]
[cpersiko@fog cs111a]$ java NestedBrackets
This program outputs a shape. How wide do you want it? 2
How tall? 5
[][]
[][]
[][]
[][]
[][]
[cpersiko@fog cs111a]$
*/
syntax highlighted by Code2HTML, v. 0.9