zoukankan      html  css  js  c++  java
  • java 代码格式(转)

    //转至博客:http://developer.51cto.com/art/201202/320317.ht

    1. /**   
    2.  * Java编码格式个人推荐,参考JDK源码和Hyperic HQ源码(原spring旗下著名开源软件,现vmware)。   
    3.  * @author lihzh(苦逼coder)   
    4.  * 本文地址:http://mushiqianmeng.blog.51cto.com/3970029/737120  
    5.  * */   
    6. public class CodeRule {   
    7.        
    8.     //声明变量,等号两边有空格。   
    9.     private static int i = 1;   
    10.        
    11.     //方法声明,右括号和左大括号中间有空格。   
    12.     public static void main(String[] args) {   
    13.         //if语句,比较连接符(>)左右有空格,小括号和大括号中间有空格。   
    14.         //if 与 左括号中间有空格   
    15.         if (i > 0) {   
    16.             System.out.println(i);   
    17.         }   
    18.         //两个条件的连接(&&),左右有空格。   
    19.         if (i > 0 && i < 2) {   
    20.             System.out.println(i);   
    21.         }   
    22.            
    23.         //if..else 语句两种格式   
    24.         //1.参考JDK,个人使用方式,else跟大括号,前后都有空格   
    25.         if (i > 0 && i < 2) {   
    26.             System.out.println(i);   
    27.         } else if (i > 2) {   
    28.             System.out.println(i + 1);   
    29.         } else {   
    30.             System.out.println(i);   
    31.         }   
    32.         //2.参考Hyperic HQ源码, else另起一行,后仍有空格   
    33.          if (i == 1) {   
    34.              System.out.println(i);   
    35.          }   
    36.          else {   
    37.              System.out.println(i);   
    38.          }   
    39.             
    40.          //while语句,与if语句类型,while与括号中间有空格,括号内格式与if相同   
    41.          while (i > 0 && i < 2) {   
    42.              System.out.println(i);   
    43.              i++;   
    44.          }   
    45.             
    46.          //for语句,两种格式   
    47.          //1.参考Hyperic HQ,个人使用方式。分号后带空格,每个子语句中,连接符左右都带空格。   
    48.          //for与括号中间带空格,大小括号中间带空格。   
    49.          for (int j = 0; j < 10; j++) {   
    50.              System.out.println(i);   
    51.          }   
    52.          //2.参考JDK,区别在于子语句中,连接符左右无空格。   
    53.          for (int j=0; j<10; j++) {   
    54.              System.out.println(i);   
    55.          }   
    56.             
    57.          //+-*/,格式,四则运算符号前后有空格。   
    58.          //在JDK的有些代码里,在方法调用的参传递或在判断语句中存在的四则运算中,四则运算符号前后无空格。   
    59.          //为了不造成困扰和混淆,个人为均保留空格。   
    60.          int a = 1 + 2;   
    61.          int b = 1 - 2;   
    62.          int c = 1 * 2;   
    63.          int d = 1 / 2;   
    64.             
    65.          //三元表达式格式,每个符号中间均有空格   
    66.          int j = i > 2 ? 1 : -1;   
    67.             
    68.          //方法声明和调用,用逗号分隔的参数,逗号后有空格。   
    69.          sum(a, b);   
    70.          sum(c + d, j);   
    71.     }   
    72.        
    73.     //方法声明,多个参数,逗号后有空格   
    74.     private static int sum(int i, int j) {   
    75.         return i + j;   
    76.     }   
    77. }  

     

  • 相关阅读:
    理解 CSS3中 object-fit
    CSS布局总结(一)
    Webpack 学习记录之概念
    python中深浅拷贝
    Vue中的动画封装
    Vue中的列表过渡
    Vue中多个元素或组件的过渡
    Vue中的Js动画与Velocity.js 的结合
    在Vue中同时使用过渡和动画
    在Vue中使用 animate.css 库
  • 原文地址:https://www.cnblogs.com/zxf330301/p/5841338.html
Copyright © 2011-2022 走看看