Introduction and wonderful use of absolute value function in Java

1、 Instructions for absolute value function

The absolute value function is math in JDK Java implementation method, which is used to get the absolute value of the expression.

Its implementation is very simple. The source code is as follows:

2、 Characteristics and application of absolute value.

1. The absolute value of a positive number is itself.

2. The absolute value of a negative number is its opposite.

3. The absolute value of zero is itself.

Absolute value: the self subtraction function matches the absolute value in descending order and then ascending order.

Output results:

3、 Case

1. Background: output the following pattern.

2. Analysis:

1. A is the center point

2. Each line is in descending order and then ascending order

3. Letters can be converted into integers, 'a' = 65. Then, the first output letter of each line is' a '+ the number of lines.

4. Each line is symmetrical left and right, and the number of output letters per line = the number of lines * 2 + 1 (letter a);

3. Realize

1. Realize steps 1 ~ 3 in the analysis. Take 'a' as the center point, and output each line of pattern in descending order and then ascending order.

The output is as follows:

2. In step 4, output letters per line = lines * 2 + 1 (letter a), then:

Print spaces for each line except the letters that should be displayed. Logic control is as follows:

3. Full code:

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>