编写一个程序 由程序中声明并给三个整数赋初值 判断这三个整数能否构成三角行

来源:百度知道 编辑:UC知道 时间:2024/05/23 01:21:36
JAVA语言基础课程上的

public class Demo {
int a, b, c;

public boolean check() {
a = 3;
b = 4;
c = 5;
int big = 0;
int total = a+b+c;

if(a>b) {
big = a;
}
if(c>big) {
big = c;
} //得到长度最大的边

int left = total - big; //较小两边之和
if(left > big) {
return true;
} else {
return false;
}
}

public Demo() {
if(check()) {
System.out.println("可以构成三角形");
} else {
System.out.println("不能构成三角形");
}
}

public static void main(String[] args) {
new Demo();
}
}

import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
int a;
int b;
int c;
System.out.println("请输入三个整数,用空格隔开:");
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();<