Welcome to Dream.In.Code
Become a Java Expert!

Join 149,597 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,885 people online right now. Registration is fast and FREE... Join Now!




pascal triangle using asterisk and using swing...

 
Reply to this topicStart new topic

pascal triangle using asterisk and using swing...

radices
8 Oct, 2007 - 04:38 AM
Post #1

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 2


My Contributions
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... rolleyes.gif

This post has been edited by PennyBoki: 8 Oct, 2007 - 04:52 AM
User is offlineProfile CardPM
+Quote Post

radices
RE: Pascal Triangle Using Asterisk And Using Swing...
10 Oct, 2007 - 01:53 AM
Post #2

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 2


My Contributions
pls help i need a result like this, for example I input 5:

.....*
....**
...***
..****
.*****
pls help me, I need this by monday....

This post has been edited by radices: 10 Oct, 2007 - 02:01 AM
User is offlineProfile CardPM
+Quote Post

sl4ck3r
RE: Pascal Triangle Using Asterisk And Using Swing...
10 Oct, 2007 - 09:47 AM
Post #3

D.I.C Head
Group Icon

Joined: 22 Sep, 2007
Posts: 119


Dream Kudos: 25
My Contributions
your not putting in the place holder periods so its not moving it over.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:31PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month