Anyone knows how to make a pascal triangle using asterisk as an output, and inputing variables using swing and ranging the variables from 1 - 100 only? I can only make an acute triangle but not a pascal triangle... here's the code please i really need your help...
CODE
import javax.swing.JOptionPane;
public class triangle1
{
public static void main(String [] args)
{
String output = "";
String Rows;
String Columns;
int rows;
int columns;
Rows = JOptionPane.showInputDialog(null,"Enter number of rows: ");
Columns = JOptionPane.showInputDialog(null,"Enter number of columns: ");
rows = Integer.parseInt(Rows);
columns = Integer.parseInt(Columns);
if (rows <= 0 || rows >= 101 || columns <= 0 || columns >= 100)
{
JOptionPane.showMessageDialog(null,"Out of Range... ");
System.exit(0);
}
if (rows == columns)
{
for (int row = 1;row <= rows;++row)
{
for (int column = 1;column <= row;++column)
{
output += "* ";
}
output += "\n" + "\n";
}
JOptionPane.showMessageDialog(null,"The output is: " + "\n" + output);
}
else if (rows != columns)
{
JOptionPane.showMessageDialog(null,"Out of Range... ");
System.exit(0);
}
System.exit(0);
}
}
[edit]: code tags
tnx...
This post has been edited by PennyBoki: 8 Oct, 2007 - 04:52 AM