class yuan
{
int b;
final double PI=3.1415926;
int mianji()
{
return (int)(PI*((double)b)*((double)b);
}
int zhouchang()
{
return (int)(2*((double)b)*PI);
}
public static void main( String[] args)
{
yuan y1=new yuan();
yuan y2=new yuan();
y1.b=2;
System.out.println("mianji of yuan="+y1.mianji());
System.out.println("zhouchang of yuan="+y1.zhouchang());
y2.b=4;
System.out.println("mianji of yuan="+y2.mianji());
System.out.println("zhouchang of yuan="+y2.zhouchang());
}
}
[此贴子已经被作者于2007-9-22 2:52:29编辑过]
----------------解决方案--------------------------------------------------------
class yuan
{
int b;
final double PI=3.1415926;
int mianji()
{
return (int)(PI*((double)b)*((double)b));//这少了一个括号,
}
int zhouchang()
{
return (int)(2*((double)b)*PI);
}
public static void main( String[] args)
{
yuan y1=new yuan();
yuan y2=new yuan();
y1.b=2;
System.out.println("mianji of yuan="+y1.mianji());
System.out.println("zhouchang of yuan="+y1.zhouchang());
y2.b=4;
System.out.println("mianji of yuan="+y2.mianji());
System.out.println("zhouchang of yuan="+y2.zhouchang());
}
}
----------------解决方案--------------------------------------------------------
Exception in thread "main" java.lang.NoSuchMethodError: main
哪的错?
----------------解决方案--------------------------------------------------------
你运行java命令的时候,类名可能写错了!!
仔细检查下
----------------解决方案--------------------------------------------------------
没有啊.不可能错的.谢谢你咯.在帮我找找问题~
----------------解决方案--------------------------------------------------------
应试是环境变量设置问题?在重设一下!
----------------解决方案--------------------------------------------------------
把你运行的代码贴出来,
呵呵,这样太抽象了!!
----------------解决方案--------------------------------------------------------
我运行的时候该一下类名yuan要大写(Yuan), 在第八行加了一个“)”就 OK了。运行的结果为:
mianji of yuan=12
zhouchang of yuan=12
mianji of yuan=50
zhouchang of yuan=25
不知正不正确啊?
----------------解决方案--------------------------------------------------------
大小没关系吧 编译时一样就可以了啊
----------------解决方案--------------------------------------------------------
import java.io.*;
class yuan
{
int b;
final double PI=3.1415926;
int mianji()
{
return (int)(PI*((double)b)*((double)b));
}
int zhouchang()
{
return (int)(2*((double)b)*PI);
}
public static void main( String[] args)throws IOException
{
yuan y1=new yuan();
yuan y2=new yuan();
int c;
System.out.println("shuru:");
c=System.in.read();
y1.b=c;
System.out.println("mianji of yuan="+y1.mianji());
System.out.println("zhouchang of yuan="+y1.zhouchang());
y2.b=4;
System.out.println("mianji of yuan="+y2.mianji());
System.out.println("zhouchang of yuan="+y2.zhouchang());
}
}
为什么我输入4后得到的结果是:
mianji of yuan=8494
zhouchang of yuan=326
mianji of yuan=50
zhouchang of yuan=25
----------------解决方案--------------------------------------------------------