反正闲着也是闲着
public static void main(String[] args) {
if(args.length == 2) {
if(args[0].equals("start")) {
Double D = new Double(args[1]);
double d = D.doubleValue();
int count = Math.abs((int)d);
int[] datas = new int[count];
for(int i = 0; i < count; i ++) {
datas[i] = (int)i * (int)d;
}
} else if(args[0] == "end") {
System.out.println("GoodBye!");
}
}
}
public static void main(String[] args) {
if(args.length == 2) {
if(args[0].equals("start")) {
Double D = new Double(args[1]);
double d = D.doubleValue();
int count = Math.abs((int)d);
int[] datas = new int[count];
for(int i = 0; i < count; i ++) {
datas[i] = (int)i * (int)d;
}
} else if(args[0] == "end") {
System.out.println("GoodBye!");
}
}
}
缩进应该是四个空格args.getLength() -->>>args.lengthdatas[i] = (int)i * d;-->>>(int)(i * d)
java和那些有些地方还是不一样的!
if(args.getLength() == 2) { *********************应该用args.length
if(args[0].equals("start")) {
Double D = args[1]; *************Double D = new Double(args[1]);
double d = D.doubleValue();
int count = Math.abs((int)d);
int[] datas = new int[];****************** 这里没做初期化
for(int i = 0; i < count; i ++) {
datas[i] = (int)i * d; ********************* datas[i] = (int)(i * d);因为i*d是double
}
} else if(args[0] == "end") {*************** args[0].equals("end")因为这样才能比较对象而不是引用
System.out.println("GoodBye!");
}
}
}
if (args.length == 2) {
if (args[0].equals("start")) {
Double D = new Double(args[1]);
double d = D.doubleValue();
int count = Math.abs((int) d);
int[] datas = new int[count];
for (int i = 0; i < count; i++) {
datas[i] = (int) (i * d);
}
} else if (args[0] == "end") {
System.out.println("GoodBye!");
}
}
}
if (args.length == 2) {
if ("start".equalsIgnoreCase(args[0])) {
Double D = Double.valueOf(args[1]);
double d = D.doubleValue();
int count = Math.abs((int) d);
int[] datas = new int[count];
for (int i = 0; i < count; i++) {
datas[i] = (int) (i * d);
}
} else if ("end".equalsIgnoreCase(args[0])) {
System.out.println("GoodBye!");
}
}
}
double d = D.doubleValue();
改为
if ("start".equals(args[0]))这是好的习惯...
菜鸟肯定看着很不习惯 :)
请问为什么那样写是好习惯?
这句话编译器是怎么去编译得,虚拟机如何解释,先后构造了一些什么对象调用了一些什么对象的什么方法,好处在哪里,哪位老鸟来说个明白透彻?
这个编译的好处我是不知道,不过至少有这么个好处:
如果你的args[0] = null,
那就惨了