是啊,我运行也是得
mianji of yuan=8494
zhouchang of yuan=326
mianji of yuan=50
zhouchang of yuan=25
怎么回事咯...
是啊,我运行也是得
mianji of yuan=8494
zhouchang of yuan=326
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.print("shuru:");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int c= Integer.parseInt(reader.readLine());
//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=c;
System.out.println("mianji of yuan="+y2.mianji());
System.out.println("zhouchang of yuan="+y2.zhouchang());
}
}
呵呵..谢谢大家的帮助咯.我现在弄明白了.这个程序就OK了.
更改三处yuan 变成 Yuan
即:
class Yuan
Yuan y1=new Yuan();
Yuan y2=new Yuan();
这样才是正确的!!!
类名首字母必须大写!!! 其余的当然跟着大写啦!!
当然在eclipse下,不用大写也是正确的!!!本人运行成功!!
一般情况下不建议使用数据的强制转换,会导致精度的损失!!!
[此贴子已经被作者于2007-9-23 23:57:06编辑过]
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.print("shuru:");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int c= Integer.parseInt(reader.readLine());
//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=c;
System.out.println("mianji of yuan="+y2.mianji());
System.out.println("zhouchang of yuan="+y2.zhouchang());
}
}
呵呵..谢谢大家的帮助咯.我现在弄明白了.这个程序就OK了.
复杂了一些,变得更加有意思了!但是新的问题又出现了,代码变得毫无意义:下面的都可以省了
yuan y2=new yuan();
y2.b=c;
System.out.println("mianji of yuan="+y2.mianji());
System.out.println("zhouchang of yuan="+y2.zhouchang());
还有System.out.print("shuru:"); "shuru"最好换成:"请输入一个整数:" 否则输入字符,小数等运行都会出错!
[此贴子已经被作者于2007-9-24 1:24:57编辑过]