A polygon is a two-dimensional closed shape with at least 3 sides. Depending on the number of sides, the relationship of the sides to angles, and other characteristics, polygons can be classified under various names such as triangles, squares, and quadrilaterals.
The definition of a convex polygon explains that it is a polygon with all angles less than 180 degrees. This also means that the vertices, the points where two edges meet, point towards the center of the shape.
In this article, we will find out whether two convex regular polygons have the same center.
We will take two sides of a convex polygon with side length "a", and two sides of a convex polygon with side length "b", where "b>a". We then need to check if an "a" sided polygon is embedded into a "b" sided polygon, whether they have the same center.
We will use the formula "b % a == 0" to find this, which means that the side of the "a" side can completely cover the "b" side, which means that both polygons have the same center.
let's start!
Suppose the value of a is 15 and the value of b is 30.
After putting the values into the formula "b % a == 0" the result will be −
Polygons have the same center
Suppose the value of a is 7 and the value of b is 22.
After putting the values into the formula "b % a == 0" the result will be −
Polygons do not have the same center
Step-1 − Declare and initialize the variables.
Second step - Check the central condition, which is "b % a == 0".
Step-3 − Print the results.
We provide solutions in different ways.
By using static input
By using user-defined methods
Let’s look at the program and its output one by one.
In this method, the values of "a" and "b" will be assigned. Then according to the algorithm, we will find out whether two convex regular polygons have the same center
The Chinese translation ofpublic class Main { //main method public static void main(String[] args){ //declaring variables int a = 7; int b = 22; //checking for condition of center if (b % a == 0){ //print if polygon have same center System.out.print("Polygon have same center"); } else { //print if polygon do not have same center System.out.print("Polygon do not have same center"); } } }
Polygon do not have same center
In this method, the given values are assigned to "a" and "b". Then a user-defined method is called by passing the given value and the algorithm determines whether the two convex regular polygons have the same center.
The Chinese translation ofpublic class Main { //main method public static void main(String[] args){ //declaring variables int a = 15; int b = 30; //calling user defined method func(a, b); } //user defined method static void func(int a, int b){ //checking for condition of center if (b % a == 0){ //print if polygon have same center System.out.print("Polygon have same center"); } else { //print if polygon do not have same center System.out.print("Polygon do not have same center"); } } }
Polygon have same center
In this article, we explored different ways to check whether two convex regular polygons have the same center using Java programming language.
The above is the detailed content of How to tell if two convex regular polygons have the same center in Java?. For more information, please follow other related articles on the PHP Chinese website!