|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package
本章总结;
public
class
A03class {
public
boolean
showA(
int
a ,
int
b ,
int
c){
boolean
con=
false
;
if
((a+b)>c&&(a+c)>b&&(c+b)>a){
con=
true
;
}
return
con;
}
public
String Shape(
int
a,
int
b,
int
c){
String shape=
""
;
if
((a==b)&&(b==c)&&(c==a)){
shape=
"等边三角形"
;
}
else
if
((a==b)||(b==c)||(c==a)){
shape=
"等腰三角形"
;
}
else
{
int
A=a*a;
int
B=b*b;
int
C=c*c;
if
((A>B+C)||(B>A+C)||(C>A+B)){
shape=
"钝角三角形"
;
}
else
if
((A==B+C)||(B==A+C)||(C==A+B)){
shape=
"直角三角形"
;
}
else
{
shape=
"锐角三角形"
;
}
}
return
shape;
}
}
package
本章总结;
import
java.util.Scanner;
public
class
A03 {
/**
* @param args
*/
public
static
void
main(String[] args) {
A03class A03=
new
A03class();
boolean
con=
true
;
while
(con){
Scanner input =
new
Scanner(System.in);
System.out .print(
"请输入第一条边:"
);
int
num1=input.nextInt();
System.out .print(
"请输入第二条边:"
);
int
num2=input.nextInt();
System.out .print(
"请输入第三条边:"
);
int
num3=input.nextInt();
if
(A03.showA(num1,num2,num3)){
System.out .print(
"这是一个"
+A03.Shape(num1, num2, num3));
}
else
{
System.out .print(
"这不能构成三角形。"
);
}
System.out .print(
"\n继续吗?(y/n):"
);
String choice=input.next();
if
(choice.equals(
"n"
)){
con=
false
;
System.out .print(
"谢谢使用!"
);
}
}
}
}
|
本文转自 Y幕徐 51CTO博客,原文链接:http://blog.51cto.com/765133133/1426631