我是一个java新手,以前学过1年多的c++最近开始学习java,发现java的代码在格式上和以前有个很大的不同的地方。public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World");
}
}
java程序中的{ }不是和以前那样对齐的,不知道这是不是java的编程风格,是不是要把以前c++的格式改成java的,希望前辈指教一下
public static void main(String[] args){
System.out.println("Hello World");
}
}
java程序中的{ }不是和以前那样对齐的,不知道这是不是java的编程风格,是不是要把以前c++的格式改成java的,希望前辈指教一下
* @(#)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);
}
}
}
看别人的代码的时候
ctrl + shift + F 重新排版一下