Share
Explore BrainMass

Java Application: Printing a square using loop

Write a java application that uses for loop, while loop, or do-while loop to print a square which has 10 X 10 lines of #, except lines 2, 4, and 6 which consist of * instead of # . Therefore the final output will look like this:

##########
**********
##########
**********
##########
**********
##########
##########
##########
##########

Solution Preview

Please rename the attached 525569-PrintSquare.java to PrintSquare.java before compiling.

You can use following instructions to compile and run the program at command prompt.

javac PrintSquare.java
java PrintSquare

Version 1.7.0_03 of Java was used in ...

Solution Summary

Solution uses nested for loops, and if-then-else statement to achieve the goal.

$2.19