Well, this weeks assignment is pretty crazy... first off, we had to make a program that would allow you to input a number, and then it would display a square made up of "*" with the dimensions of whatever number you inputted... (i.e. "4" would make a square * * * * and 4 lines down)
Just noticed that for the assigment the square must be displayed using JOptionPane.showMessageDialog...can soemone show me how to do this the simple way? I tried, but for some reason I just can't get it to work.
Next Problem is to make a program to display a triangle like the square above.. I figure I need to set the loop to remove a star for every count-- on the height loop... but how do I do that? Adding a star is easy, taking one away is confusing
I am supposed to use the same code above and just alter it.
Thanks for any help
Anthony
Code:
import javax.swing.JOptionPane;
public class SquareDraw {
public static void main( String[] args) {
int dimen =
Integer.parseInt( JOptionPane.showInputDialog(
"Enter the size of the square.") );
int control1, control2;
control1 = dimen;
while( control1 > 0 ) {
control2 = dimen;
while( control2 > 0 ) {
System.out.print( "* " );
control2 --;
}
System.out.println();
control1--;
}
System.exit( 0 );
}
}
Just noticed that for the assigment the square must be displayed using JOptionPane.showMessageDialog...can soemone show me how to do this the simple way? I tried, but for some reason I just can't get it to work.
Next Problem is to make a program to display a triangle like the square above.. I figure I need to set the loop to remove a star for every count-- on the height loop... but how do I do that? Adding a star is easy, taking one away is confusing
Thanks for any help
Anthony