我是一个java新手,以前学过1年多的c++最近开始学习java,发现java的代码在格式上和以前有个很大的不同的地方。public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World");
}
}
java程序中的{ }不是和以前那样对齐的,不知道这是不是java的编程风格,是不是要把以前c++的格式改成java的,希望前辈指教一下

解决方案 »

  1.   

    嗯,可以去看看 Sun 公司的 Java Coding Style Guide 小册子,不多只有20来页,无意之中找到的。我在这里贴过不知道多少次了。http://developers.sun.com/sunstudio/products/archive/whitepapers/java-style.pdf
      

  2.   

    下面的这个就是上面那个手册中的代码样例,其他的诸如类名、方法名和变量名的要求可以去看看那个手册。/**
     * @(#)CodingStyleExample.java       1.0 98/01/23 Achut Reddy
     *
     * Copyright (c) 1994-1998 Sun Microsystems, Inc. All Rights Reserved.
     */package com.sun.examples;import java.applet.Applet;
    import java.awt.Point;/**
     * A class to demonstrate good coding style.
     */
    public class CodingStyleExample extends Applet implements Runnable {    static final int BUFFER_SIZE = 4096;      // default buffer size
        StringBuffer     name;                    // my name
        Point            starshipCoordinates[];   // ship locations    /**
         * Compute the total distance between a set of Points.
         * @param starshipCoordinates the locations of all known starships
         * @param numberOfPoints      the number of points in the array
         * @return the total distance
         */
        public int computeDistances(Point starshipCoordinates[],
                                    int numberOfPoints) throws Exception {
            int distance = 0;                    // accumulates distances        // Compute distance to each starship and add it to the total
            for (int i = 0; i < numberOfPoints; i++) {
                distance += Math.sqrt((double)((starshipCoordinates[i].x *
                                                starshipCoordinates[i].x) +
                                                (starshipCoordinates[i].y *
                                                 starshipCoordinates[i].y)));
            }        if (distance > 100000) {
                throw new Exception();
            }        return distance;
        }    /**
         * Called whenever Thread.start() is called for this class
         */
        public void run() {
            try {
                name.append("X");
                System.out.println(name);
            } catch (Exception e) {
                name = new StringBuffer(BUFFER_SIZE);
            }
        }
    }
      

  3.   

    自己看着习惯就行
    看别人的代码的时候 
    ctrl + shift + F 重新排版一下