Go to Blog: http://developer.51cto.com/art/201202/320317.ht
- /**
- * Java Encoding Format Personal recommendation, refer to JDK source code and Hyperic HQ source code (formerly spring's famous open source software, now VMware).
- * @author Lihzh (bitter force coder)
- * This address: http://mushiqianmeng.blog.51cto.com/3970029/737120
- * */
- Public class Coderule {
- //Declare variable with a space on both sides of the equal sign.
- private static int i = 1;
- //method declaration, with a space between the closing parenthesis and the left curly brace.
- public static void Main (string[] args) {
- The//if statement, the comparison connector (>) has spaces around it, and a space between the parentheses and the curly braces.
- //if and left parenthesis have spaces between them
- if (i > 0) {
- System.out.println (i);
- }
- //Two conditions of connection (&&), there are spaces left and right.
- if (i > 0 && i < 2) {
- System.out.println (i);
- }
- //if. Else Statement two formats
- //1. Reference JDK, personal use, else with curly braces, spaces before and after
- if (i > 0 && i < 2) {
- System.out.println (i);
- } Else if (i > 2) {
- System.out.println (i + 1);
- } Else {
- System.out.println (i);
- }
- //2. Refer to Hyperic HQ source code, else another line, and then there are still spaces
- if (i = = 1) {
- System.out.println (i);
- }
- else {
- System.out.println (i);
- }
- //while statement, with an if statement type, while with a space in the middle of parentheses, with the same format as if
- While (i > 0 && i < 2) {
- System.out.println (i);
- i++;
- }
- //for statements, two formats
- //1. Refer to Hyperic HQ, personal use mode. The semicolon is followed by a space, and in each child statement, there are spaces around the connector.
- //for with spaces in the middle of parentheses, with spaces in the middle of the size brackets.
- For (int j = 0; j < ; J + +) {
- System.out.println (i);
- }
- //2. Refer to the JDK, except that the connector has no spaces left or right in the child statement.
- For (int j=0; j<; j + +) {
- System.out.println (i);
- }
- //+-*/, format, arithmetic sign before and after a space.
- //In some code in the JDK, there are no spaces before or after the arithmetic symbol in the arithmetic of a method invocation or in a judgment statement.
- //In order not to cause distress and confusion, the individual retains the space.
- int a = 1 + 2;
- int b = 1- 2;
- int c = 1 * 2;
- int d = 1/ 2;
- //ternary expression format with spaces in the middle of each symbol
- Int J = i > 2? 1:-1;
- //method declaration and invocation, separated by commas, with a comma followed by a space.
- Sum (A, b);
- SUM (c + D, j);
- }
- //method declaration, multiple parameters, comma followed by a space
- private static int sum (int i, int j) {
- return i + j;
- }
- }
Java code Format (RPM)