展开全部
import java.util.Arrays;
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入第一条边的长度:");
int a = input.nextInt();
System.out.print("请输入第二条边的长度:");
int b = input.nextInt();
System.out.print("请输入第三条边的长度:");
int c = input.nextInt();
System.out.println(new Triangle(a,b,c));
}
private int[] brims;
public Triangle() {
}
public Triangle(int a,int b,int c) {
brims = new int[3];
brims[0] = a;
brims[1] = b;
brims[2] = c;
Arrays.sort(brims);
}
public int[] getBrims() {
return brims;
}
public boolean isTriangle(){
if(brims[0]+brims[1]>brims[2]) {
return true;
}
return false;
}
public void setBrims(int[] brims) {
this.brims = brims;
}
public String toString() {
String str;
if(isTriangle()) {
str = "三角形的三边长分别为 :" + brims[0] + " ," + brims[1] + " ," + brims[2];
} else {
str = "这不是一个三角形";
}
return str;
}
}
import java.util.Scanner;
public class Triangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入第一条边的长度:");
int a = input.nextInt();
System.out.print("请输入第二条边的长度:");
int b = input.nextInt();
System.out.print("请输入第三条边的长度:");
int c = input.nextInt();
System.out.println(new Triangle(a,b,c));
}
private int[] brims;
public Triangle() {
}
public Triangle(int a,int b,int c) {
brims = new int[3];
brims[0] = a;
brims[1] = b;
brims[2] = c;
Arrays.sort(brims);
}
public int[] getBrims() {
return brims;
}
public boolean isTriangle(){
if(brims[0]+brims[1]>brims[2]) {
return true;
}
return false;
}
public void setBrims(int[] brims) {
this.brims = brims;
}
public String toString() {
String str;
if(isTriangle()) {
str = "三角形的三边长分别为 :" + brims[0] + " ," + brims[1] + " ," + brims[2];
} else {
str = "这不是一个三角形";
}
return str;
}
}
展开全部
三角形远离:任意两边之和大于第三边,任意两边之和小于第三边。有了这个思路我们就可以动手写程序了:
public static boolean validate(int a,int b, int c){
if((a + b >c && a - b < c) && (a + c > b && a - c < b) && (b + c > a && b - c < a)){
System.out.println(a +", " + b +", " + c +" 可以组成三角形!");
return true;
}else {
System.out.println(a +", " + b +", " + c +" 不能组成三角形!");
return false;
}
}
public static boolean validate(int a,int b, int c){
if((a + b >c && a - b < c) && (a + c > b && a - c < b) && (b + c > a && b - c < a)){
System.out.println(a +", " + b +", " + c +" 可以组成三角形!");
return true;
}else {
System.out.println(a +", " + b +", " + c +" 不能组成三角形!");
return false;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
帮你写了一个简单的方法:经测试无误
public static void main(String[] ags){
int a = 12;
int b = 1;
int c = 2;
if(a>0&&b>0&&c>0&&a+b>c&&a+c>b&&b+c>a){
System.out.println(a +", " + b +", " + c +" 可以组成三角形!");
}else {
System.out.println(a +", " + b +", " + c +" 不能组成三角形!");
}
}
public static void main(String[] ags){
int a = 12;
int b = 1;
int c = 2;
if(a>0&&b>0&&c>0&&a+b>c&&a+c>b&&b+c>a){
System.out.println(a +", " + b +", " + c +" 可以组成三角形!");
}else {
System.out.println(a +", " + b +", " + c +" 不能组成三角形!");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main(String[] args) {
System.out.println(getA(0,-5,5));
}
public static String getA(int a,int b,int c){
boolean returnFlag=true;
String returnString="";
if(a<=0|b<=0|c<=0)
returnFlag=false;
if((a+b)<c&& (a - b) > c)
returnFlag=false;
if((b+c)<a&&(b-c)>a)
returnFlag=false;
if((a+c)<b&&(a-c)>b)
returnFlag=false;
if(returnFlag){
returnString="第一条边:"+(a+b)+";"+"第二条边"+(b+c)+";"+"第三条边:"+(a+c);
}else{
returnString="不能构成三角形";
}
return returnString;
}
System.out.println(getA(0,-5,5));
}
public static String getA(int a,int b,int c){
boolean returnFlag=true;
String returnString="";
if(a<=0|b<=0|c<=0)
returnFlag=false;
if((a+b)<c&& (a - b) > c)
returnFlag=false;
if((b+c)<a&&(b-c)>a)
returnFlag=false;
if((a+c)<b&&(a-c)>b)
returnFlag=false;
if(returnFlag){
returnString="第一条边:"+(a+b)+";"+"第二条边"+(b+c)+";"+"第三条边:"+(a+c);
}else{
returnString="不能构成三角形";
}
return returnString;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Triangle
{
public static void main(String[] args)
{
int side = new int[3];
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 3; i++)
{
side[i] = sc.nextInt();
}
boolean flag = true;
for(int i = 0; i < 3; i++)
{
if(side[i] >= side[i+1] % 3 + side[i + 2] % 3)
{
flag = false;
break;
}
}
if(flag == true)
{
System.out.println("The three sides of the triangle are: ");
for(i = 0; i < 3; i++)
System.out.println(side[i]);
}
else
System.out.println("The three integer can't be the sides of a triangle");
}
{
public static void main(String[] args)
{
int side = new int[3];
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 3; i++)
{
side[i] = sc.nextInt();
}
boolean flag = true;
for(int i = 0; i < 3; i++)
{
if(side[i] >= side[i+1] % 3 + side[i + 2] % 3)
{
flag = false;
break;
}
}
if(flag == true)
{
System.out.println("The three sides of the triangle are: ");
for(i = 0; i < 3; i++)
System.out.println(side[i]);
}
else
System.out.println("The three integer can't be the sides of a triangle");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询