FRANKIESANTOS
February 20th, 2000, 07:13 PM
I need help with writing this program below. I can't seem to get the program to draw a diamond. I can only make a box. It is for homework on Tuesday, Feb.22nd. I appreciate any help I can get. Thanks.
//This program will read an odd number in the range of 1-19
//to specify the number if rows in a diamond and then display
//that diamond of the appropriate size.
import javax.swing.JOptionPane;
public class SF01 {
public static void main( String args [] )
{
int oddNumber;
String output = "";
String input;
int whiteSpace;
//read in the odd number for the diamond
input = JOptionPane.showInputDialog(
"Enter any odd number between 1 and 19:");
//convert numbers from type String to type int
oddNumber = Integer.parseInt (input);
int row =1;
for ( row = 1; row <= oddNumber; row++) {
//for (whiteSpace = oddNumber; whiteSpace >= row; --whiteSpace) {
// output += " ";
int column =1;
for ( column =1; column <=oddNumber; column++) {
output += "* ";
}
output += "\n";
}
//display the results
JOptionPane.showMessageDialog (
null, output, "Results",
JOptionPane.PLAIN_MESSAGE );
System.exit (0);
}
}
//This program will read an odd number in the range of 1-19
//to specify the number if rows in a diamond and then display
//that diamond of the appropriate size.
import javax.swing.JOptionPane;
public class SF01 {
public static void main( String args [] )
{
int oddNumber;
String output = "";
String input;
int whiteSpace;
//read in the odd number for the diamond
input = JOptionPane.showInputDialog(
"Enter any odd number between 1 and 19:");
//convert numbers from type String to type int
oddNumber = Integer.parseInt (input);
int row =1;
for ( row = 1; row <= oddNumber; row++) {
//for (whiteSpace = oddNumber; whiteSpace >= row; --whiteSpace) {
// output += " ";
int column =1;
for ( column =1; column <=oddNumber; column++) {
output += "* ";
}
output += "\n";
}
//display the results
JOptionPane.showMessageDialog (
null, output, "Results",
JOptionPane.PLAIN_MESSAGE );
System.exit (0);
}
}