Climbing的专栏

Life is limited, but art is long

huang ClimbingID:hpdlzu80100
3194次访问,排名2万外好友4人,关注者7
热爱生活,积极向上,流自己的汗,吃自己的饭!
hpdlzu80100的文章
原创 23 篇
翻译 0 篇
转载 5 篇
评论 1 篇
最近评论
diqizhan:很喜欢这个
文章分类
收藏
    相册
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 勾股数列表(Find Pythagorean Triples)收藏

    新一篇: 大小可变钻石形状(Display a diamond shape constituted by asterisks) | 旧一篇: 170以内阶乘表(Factorial list up to 170)

    //Find Pythagorean Triples within 500
    //Java how to program, 5/e, Exercise 5.17
    import javax.swing.*;
    public class PythagoreanTriples {
        
    public static void main (String arg[])
       
    {
            
    boolean guard;
            
    int counter=1, number;
            String Number;
            Number
    =JOptionPane.showInputDialog("Enter the limit number:");
            number
    =Integer.parseInt(Number);
            JTextArea output
    =new JTextArea(17,20);
            JScrollPane scroller
    =new JScrollPane(output);
            output.setText(
    "N1\t N2\tN3\t");
            
    for (int i=1;i<=number;i++)
                
    {for (int j=i+1;j<=number;j++)
                    
    {for (int k=j+1;k<=number;k++)
                        
    {guard=i*i+j*j==k*k;
                        
    if (guard)
                            
    {output.append(i+"\t "+j+" \t"+k+" \t");
                        counter
    ++;}

                        }

                    }

                }

            output.append(
    " Total Pythagorean Triples number:"+counter);
            JOptionPane.showMessageDialog(
    null, scroller,"Pythagorean Triples",
                    JOptionPane.INFORMATION_MESSAGE);
        }

    }

     

    发表于 @ 2008年04月09日 10:06:00|评论(loading...)|编辑

    新一篇: 大小可变钻石形状(Display a diamond shape constituted by asterisks) | 旧一篇: 170以内阶乘表(Factorial list up to 170)

    评论

    #diqizhan 发表于2008-06-10 01:56:09  IP: 61.142.111.*
    很喜欢这个
    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © Climbing