Climbing的专栏
Life is limited, but art is long
登录
注册
全站
当前博客
空间
博客
好友
相册
留言
huang Climbing
ID:hpdlzu80100
共
3194
次访问,排名
2万外
好友
4
人,关注者
7
人
热爱生活,积极向上,流自己的汗,吃自己的饭!
hpdlzu80100的文章
原创 23 篇
翻译 0 篇
转载 5 篇
评论 1 篇
最近评论
diqizhan:
很喜欢这个
文章分类
IT Industry and Career
(RSS)
Java Learning
(RSS)
Software Testing
(RSS)
Temp
(RSS)
收藏
相册
存档
2008年05月(4)
2008年04月(24)
软件项目交易
订阅我的博客
勾股数列表(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.*
很喜欢这个
发表评论
姓 名:
主 页:
校验码:
看不清,换一张
登录