[英]Java getting output from program executed in command line when it constantly updates a single line in the command prompt
[英]Not getting correct output when using command line argument in java
//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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.