永发信息网

Java编程对象输入任意三个数,判断是什么样的三角形((编了一些,不行(定义两个方法

答案:5  悬赏:80  手机版
解决时间 2021-01-30 06:37
  • 提问者网友:wodetian
  • 2021-01-29 16:38
Java编程对象输入任意三个数,判断是什么样的三角形((编了一些,不行(定义两个方法
最佳答案
  • 五星知识达人网友:山君与见山
  • 2021-01-29 18:06
public class Test{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int num[] = new int[3];
while(true){
System.out.println("请输入三角形的三条边:");

for(int i=0;i<3;i++){
System.out.print("请输入三角形的第"+(i+1)+"条边:");
num[i] = scan.nextInt();
}

int temp;
for(int j=0;j<num.length-1;j++){
if(num[j]<num[j+1]){
temp = num[j];
num[j] = num[j+1];
num[j+1] = temp;
}
}
int a = num[0];
int b = num[1];
int c = num[2];
if(b+c>a){
if(a == b&&b == c){
System.out.println("等边三角形");
}else if(b == c){
System.out.println("等腰三角形");
}else if(b*b+c*c>a*a){
System.out.println("锐角三角形");
}else if(b*b+c*c==a*a){
System.out.println("直角三角形");
}else if(b*b+c*c<a*a){
System.out.println("钝角三角形");
}
}else{
System.out.println("输入的三个数不能构成三角形");
}
}
}
}
全部回答
  • 1楼网友:轻熟杀无赦
  • 2021-01-29 22:41
public class Judge { public static void a(int a,int b,int c){ if(a+b<c || a+c<b || b+c<a){ System.out.println("你输入的不能构成三角形"); } } public static void b(int a,int b,int c){ if(a==b || a==c || b==c) { if(a==b && b==c) System.out.println("等边三角形"); } } public static void c(int a,int b,int c){ if(a==b || a==c || b==c) { if(a==b && b==c){ } else{  System.out.println("等腰三角形"); } } } public static void d(int a,int b,int c){ if(a==b || a==c || b==c){ } else{ System.out.println("一般三角形"); } }  }我好像认识你 或者是 public class Test { public static int a, b, c; public static void main(String arg[]) throws IOException {   try {    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));    System.out.println("输入三边值,每个值输入后回车");    System.out.println("请输入:");    a = Integer.valueOf(stdin.readLine());    b = Integer.valueOf(stdin.readLine());    c = Integer.valueOf(stdin.readLine());    checkTriangle(a,b,c);   }   catch (IOException e) {    System.out.println("出现异常!");    System.exit(0);   }  }  public static void checkTriangle(int a,int b,int c){   if (a + b < c || a + c < b || b + c < a) {    System.out.println("你输入的不能构成三角形");   }   if (a == b || a == c || b == c) {    if (a == b && b == c)     System.out.println("等边三角形");    else     System.out.println("等腰三角形");   }   else {    System.out.println("一般三角形");   }   if(a+b+c>30) {    System.out.println("三角形周长是" +(a+b+c));   }else {    System.out.println("三角形三边长分别是:" + a + " " + b + " " + c);   }  } }
  • 2楼网友:从此江山别
  • 2021-01-29 21:49
package Demo01; import java.util.Scanner; public class Demo08 { public static void main(String[] args) { double a, b, c; Scanner scanner = new Scanner(System.in); System.out.print("请输入第1条边:"); a = scanner.nextDouble(); System.out.print("请输入第2条边:"); b = scanner.nextDouble(); System.out.print("请输入第3条边:"); c = scanner.nextDouble(); IsTriangle(a, b, c); } public static void IsTriangle(double a, double b, double c) { if (a + b < c || a + c < b || b + c < a) { print(7, a, b, c); return; } if (a == b && b == c) { print(1, a, b, c); return; } if (a == b || b == c || a == c) { if (c * c == a * a + b * b || a * a == c * c + b * b || b * b == a * a + c * c) { print(3, a, b, c); return; } else { print(2, a, b, c); return; } } if (c * c == a * a + b * b || a * a == c * c + b * b || b * b == a * a + c * c) { print(4, a, b, c); return; } if (c * c > a * a + b * b || a * a > c * c + b * b || b * b > a * a + c * c) { print(5, a, b, c); } else { print(6, a, b, c); } } public static void print(int i, double a, double b, double c) { String str = ""; switch (i) { case 1: str = "等边三角形"; break; case 2: str = "等腰三角形"; break; case 3: str = "等腰直角三角形"; break; case 4: str = "直角三角形"; break; case 5: str = "钝角三角形"; break; case 6: str = "锐角三角形"; break; default: str = "不能构成三角形"; break; } System.out.println("您输入三边为:" + a + "," + b + "," + c + "的三角形是:" + str); } }
  • 3楼网友:野慌
  • 2021-01-29 20:33
首先是能组成三角形的情况下,进行下面判断, 1,两个短边的平方和小于第三个数的平方为钝角三角形; 2,两个短边的平方和等于第三个数的平方为直角三角形; 3,两个短边的平方和大于第三个数的平方为锐角三角形;
  • 4楼网友:蓝房子
  • 2021-01-29 18:56
按照你的要求编写的java程序如下: import java.util.scanner; public class d {  public static void main(string[] args) {   scanner sc=new scanner(system.in);   system.out.println("请输入三角形的三个边:");   int a=sc.nextint();   int b=sc.nextint();   int c=sc.nextint();   if((a+b<=c)||(a+c<=b)||(b+c<=a)){    system.out.println("这不是三角形!");   }else if(a==b && b==c){    system.out.println("这是等边三角形!");   }else if(a==b||b==c||a==c){    system.out.println("这是等腰三角形!");   }else if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b){    system.out.println("这是直角三角形!");   }else if((a*a+b*b>c*c)||(a*a+c*c>b*b)||(b*b+c*c>a*a)){    system.out.println("这是锐角三角形!");   }else if((a*a+b*b    system.out.println("这是钝角三角形!");   }  } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯