In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian introduces in detail for you "Java how to create a hollow diamond with a two-dimensional array" with detailed content, clear steps and proper handling of details. I hope this article "Java how to create a hollow diamond with a two-dimensional array" can help you solve your doubts.
How to create a hollow diamond with a two-dimensional array
Provide my own implementation method, the realization of the method is only a person's way, not on behalf of strength, the real strength to use their own thinking to solve other people's urgent problems, is really the meaning of programming. I feel refreshed after drinking the chicken soup. Let's take a look at my example.
Topic: create a diamond hollow with "*"
In order to better find out the relationship between horizontal and vertical coordinates, I simply made a diamond diagram.
Figure 1. Diamond shape
The meaning of * points and coordinate values can be found from the diagram, so this problem is done with two-dimensional coordinates.
The output image is divided into two parts, and the upper part:
Blossom from the middle, assign the value on both sides to 1, otherwise it is 0, and finally output the * sign to the point assigned to 1.
Defines the bit int [] a=new int [13] [13] of a two-dimensional array
Define two points in the column direction, p1 and p2, that is, a [I] [p1], a [I] [p2]
So from figure 2, you can see that point An and BMagne C can tell p1=a.length/2-i (in the programming process, I is 0grade. recall 2 is also the midpoint of a line), p2centa.bearthbind 2quoi; B (iMaginp1), C (iMaginp2)
Figure 2. Diamond shape
Why is it divided into two parts? because in a.lengh/2-i, it is negative when I equals 7, so we can't always use the original value of p1 and p2. We need to find the law of horizontal and vertical coordinates again.
The second half:
The coordinate of D is (igravium italk a.paradthbin2), that is, D (irecoverp3), and the coordinate of E is more difficult to find the relationship. I also thought about it for a long time. Ha ha, I just kept trying, but in the end, I couldn't try it out. It was only by drawing and analyzing that I could find the rule. So the scientific method is to use mathematical thinking to find the position relationship of horizontal and vertical coordinate points.
Fig. 3 coordinate analysis of point E
Specific implementation code:
Package com.JavaBase; public class lingxing {/ / rhomboid public static void main (String [] args) {int n = 15 * (int +) {a [I] [j] = 0; int p1 = a.length / 2-I; int p2 = a [I] .length / 2 + I Tinct hand p1 and p2 is very easy to find if (I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 262
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.