这是一个算平方根的例子,Math.sqrt(),
class Root{
public static void main(String[] arguments){
int number = 255 ;
System.out.print("The square root of "
+ number
+ " is "
+ Math.sqrt(number)
);
}
}
但是想算其它任意数的平方根要怎么做呢,他没有讲,而是在练习题里布置了作业,但是在他的网站上有答案,虽然全是英文,但是代码都能懂。http://workbench.cadenhead.org/book/java-7-24-hours/
但是他讲清楚了参数的使用方法,就向下面这个网友所描述的。
可以参考百度网友的解释:N维向量http://zhidao.baidu.com/question/19764316.html
在运行时输入java test xx yy zz,并且在你的main函数里面加这段话:System.out.println("arg is"+args[0]+" "+args[1]+" "+args[2]),然后看看输出是什么?
是不是:
arg is xx yy zz
然后我就看了答案:
class BlankFiller {
public static void main(String[] args) {
int number = Integer.parseInt(args[0]);
System.out.println("The square root of "
+ number
+ " is "
+ Math.sqrt(number)
);
}
}
这句是关键,将arg[0]第一个参数转换成基本数据类型int(整数)