Method to determine whether a triangle is a triangle in java: (Recommended: java video tutorial)
package Angle; import java.util.Scanner; public class Angle { //判断是否能构成三角形 public static int JudgeAngle(int a,int b,int c) { if(a+b>c&&a+c>b&&b+c>a) { System.out.println("能够构成三角形!"); return 1; } else { System.out.println("不能构成三角形!"); return 0; } } //判断是否能构成等腰三角形 public static int JudgeDangle(int a,int b,int c) { if(a==b||a==c||b==c) { if(a==b&&a==c) { System.out.println("该三角形是等边三角形!"); return 1; } else { System.out.println("该三角形是普通的等腰三角形!"); return 1; } } else { return 0; } } //判断是否是直角三角形 public static int JudgeRangle(int a,int b,int c) { int r1,r2,r3; r1=a*a+b*b-c*c; r2=a*a+c*c-b; r3=b*b+c*c-a*a; /*System.out.println(r1+r2+r3);*/ if(r1==0||r2==0||r3==0) { System.out.println("该三角形是直角三角形!"); return 1; } else { //System.exit(0); return 0; } } public static void main(String [] args) { int a; int b; int c; System.out.println("请输入三角形的三边: "); Scanner scanner=new Scanner(System.in); a=scanner.nextInt(); b=scanner.nextInt(); c=scanner.nextInt(); //判断输入三边是否合法 if(a<0||a>200||b<0||b>200||c<0||c>200) { System.out.println("你输入的三边不合法!"); } else { //判断是否能构成三角形 JudgeAngle(a,b,c); //判断是否是等腰或等边三角形 JudgeDangle(a,b,c); //判断是否是直角三角形 JudgeRangle(a,b,c); //判断是一般三角形 System.out.println("该三角形是一般三角形!"); } } }
The above code determines by judging the length of the three sides Triangular or not.
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Java method to determine whether it is a triangle (code attached). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
