After these several code submissions, found that many people's code style is not standardized. Personally, it is necessary to impose a code specification.
Overall, there are three code styles, two of which are similar to this:
Public void function () { //function Body}
Obviously, the code becomes difficult to read in cases where multiple blocks of code are nested.
The programmer must remember that the code is written for others to read, absolutely absolutely avoid writing (write-only) code. A good code style is bound to use two points: indentation (indent) and proper line wrapping.
The style of my code is this:
Public void function () { //function Body}
Note that the curly brace pair (brace pair) is aligned for a simple reason:
public void Function1 () { for (int i = 0; I < 10; I ++ for (int j = 0; J < 10; J ++ // some code
Public void function2 () { for (int i = 0; i <, i++) { for (int
j = 0; J < 10; J + +) { //Some code } }}
Which one would you say is easy to see and which looks comfortable?
Okay, don't say much, let's talk about how to set your own code style in eclipse:
Step One: window->preferences on the menu
Step: Enter code in the search box
Step Three: Select Java->formatter, click New ... button (i.e. under Eclipse [built-in])
Step Four: Enter your preferred name in Profile name. Here take Myjavastyle as an example:
Step Five: In the Indentation tab, tick "statements within ' switch ' body"
Step Six: In the Braces tab, except for anonymous class declaration, the other select all next line
Step Seven: In the Control Statements tab, TICK:
Step Eight:apply->ok-ok ...
Set your own Eclipse code style (internal)