//Square root of a no. using command line argument
class Calculator {
double i;
double x = Math.sqrt(i);
}
class SquareRoot {
public static void main(String arg[]) {
Calculator a = new Calculator();
a.i = Integer.parseInt(arg[0]);
System.out.println("The square root of " + a.i + " is " + a.x);
}
}
我的输出:
The square root of 64 is 0.0
我的代码有什么问题?
试试这个 :
class Calculator {
double i, x;
void squareRoot() {
x = Math.sqrt(i);
}
}
class SquareRoot {
public static void main(String arg[]) {
Calculator a = new Calculator();
a.i = Integer.parseInt(arg[0]);
a.squareRoot();
System.out.println("The square root of " + a.i + " is " + a.x);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句