l****y 发帖数: 92 | 1 我刚接触java,编了一个入门程序,
有两个问题请教大家
import java.lang.Double;
public class CircleArea
{
public static void main(String args[])
{
final double PI = 3.14;
double area, r;
r = Double.parseDouble(args[0]);
area = PI * r * r;
System.out.println("r=" + r + " area=" + area);
}
}
1,由于lang在lib\src的java目录中,所以我的classpath设置为
classpath=d:\jdk\lib\rt.jar;d:\jdk\lib\tools.jar;d:\jdk\lib\src, 这样正确吗
?
2,程序编译成功,可是运行是总是有错误提示
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException,
请问怎么解决啊???
谢谢 | xt 发帖数: 17532 | 2
Use Math.PI
This is the culprit, I think
Maybe, but you don't have to set any classpath on this piece of code.
You probably did not put any command line argument
【在 l****y 的大作中提到】 : 我刚接触java,编了一个入门程序, : 有两个问题请教大家 : import java.lang.Double; : public class CircleArea : { : public static void main(String args[]) : { : final double PI = 3.14; : double area, r; : r = Double.parseDouble(args[0]);
|
|