Java code format

Source: Internet
Author: User
Tags arithmetic

Go to Blog: http://developer.51cto.com/art/201202/320317.ht

  1. /**
  2. * Java Encoding Format Personal recommendation, refer to JDK source code and Hyperic HQ source code (formerly spring's famous open source software, now VMware).
  3. * @author Lihzh (bitter force coder)
  4. * This address: http://mushiqianmeng.blog.51cto.com/3970029/737120
  5. * */
  6. Public class Coderule {
  7. //Declare variable with a space on both sides of the equal sign.
  8. private static int i = 1;
  9. //method declaration, with a space between the closing parenthesis and the left curly brace.
  10. public static void Main (string[] args) {
  11. The//if statement, the comparison connector (>) has spaces around it, and a space between the parentheses and the curly braces.
  12. //if and left parenthesis have spaces between them
  13. if (i > 0) {
  14. System.out.println (i);
  15. }
  16. //Two conditions of connection (&&), there are spaces left and right.
  17. if (i > 0 && i < 2) {
  18. System.out.println (i);
  19. }
  20. //if. Else Statement two formats
  21. //1. Reference JDK, personal use, else with curly braces, spaces before and after
  22. if (i > 0 && i < 2) {
  23. System.out.println (i);
  24. } Else if (i > 2) {
  25. System.out.println (i + 1);
  26. } Else {
  27. System.out.println (i);
  28. }
  29. //2. Refer to Hyperic HQ source code, else another line, and then there are still spaces
  30. if (i = = 1) {
  31. System.out.println (i);
  32. }
  33. else {
  34. System.out.println (i);
  35. }
  36. //while statement, with an if statement type, while with a space in the middle of parentheses, with the same format as if
  37. While (i > 0 && i < 2) {
  38. System.out.println (i);
  39. i++;
  40. }
  41. //for statements, two formats
  42. //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.
  43. //for with spaces in the middle of parentheses, with spaces in the middle of the size brackets.
  44. For (int j = 0; j < ; J + +) {
  45. System.out.println (i);
  46. }
  47. //2. Refer to the JDK, except that the connector has no spaces left or right in the child statement.
  48. For (int j=0; j<; j + +) {
  49. System.out.println (i);
  50. }
  51. //+-*/, format, arithmetic sign before and after a space.
  52. //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.
  53. //In order not to cause distress and confusion, the individual retains the space.
  54. int a = 1 + 2;
  55. int b = 1- 2;
  56. int c = 1 * 2;
  57. int d = 1/ 2;
  58. //ternary expression format with spaces in the middle of each symbol
  59. Int J = i > 2?   1:-1;
  60. //method declaration and invocation, separated by commas, with a comma followed by a space.
  61. Sum (A, b);
  62. SUM (c + D, j);
  63. }
  64. //method declaration, multiple parameters, comma followed by a space
  65. private static int sum (int i, int j) {
  66. return i + j;
  67. }
  68. }

Java code Format (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.