Java method to determine whether it is a triangle (code attached)
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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is
