当前位置: 代码迷 >> Java相关 >> 圆的面积和周长的程序,不知道哪错了.
  详细解决方案

圆的面积和周长的程序,不知道哪错了.

热度:272   发布时间:2007-09-22 02:12:48.0
圆的面积和周长的程序,不知道哪错了.
我是新手,刚学的.不知道这个程序错在哪了..请高手指点!!谢谢.不胜感激~





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());
}
}

----------------解决方案--------------------------------------------------------
回复:(george_vcool)class yuan { int b; ...
谢谢楼上,我改了后,怎么运行它提示这个:
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


----------------解决方案--------------------------------------------------------
  相关解决方案