Home > Java > JavaBase > body text

Introduction to the method of determining whether it is a triangle in java

Release: 2019-11-22 09:49:32
Original
5377 people have browsed it

Introduction to the method of determining whether it is a triangle in java

Write a method void triangle(int a, int b, int c) to determine whether the three parameters can form a triangle. If it cannot be formed, an exception IllegalArgumentException will be thrown and the exception information will be displayed: a, b, c "Cannot form a triangle"; if it can be formed, the three side lengths of the triangle will be displayed. In the main method, get the three integers input from the command line, call this method, and catch the exception.

a

The sum of the two sides is greater than the third side: a b>c

The difference between the two sides is less than the third side: c-a

Run results:

Introduction to the method of determining whether it is a triangle in java

For more java knowledge, please pay attention to java basic tutorial.

The above is the detailed content of Introduction to the method of determining whether it is a triangle in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template