用java编写一个应用程序,要求用户输入一个圆的半径(double类型),然后计算并输出圆的直径、周长、面积
1个回答
展开全部
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Round{
public double diameter(double d){
return d*2;
}
public double perimeter(double d){
return 2*d*3.14;
}
public double area(double d){
return d*d*3.14;
}
}
public class OperateDemo{
public static void main(String args[]){
Round round=new Round();
double temp=0.0;
System.out.print("请输入圆的半径-->");
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String str=null;
try{
str=buf.readLine();
}catch(IOException e){
e.printStackTrace();
}
temp=Double.parseDouble(str);
System.out.print("改圆的直径为-->"+round.diameter(temp)+"\n"+
"改圆的周长为-->"+ round.perimeter(temp)+"\n"+
"改圆的面积为-->"+ round.area(temp));
}
}
楼主别忘了给分啊~~~
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Round{
public double diameter(double d){
return d*2;
}
public double perimeter(double d){
return 2*d*3.14;
}
public double area(double d){
return d*d*3.14;
}
}
public class OperateDemo{
public static void main(String args[]){
Round round=new Round();
double temp=0.0;
System.out.print("请输入圆的半径-->");
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String str=null;
try{
str=buf.readLine();
}catch(IOException e){
e.printStackTrace();
}
temp=Double.parseDouble(str);
System.out.print("改圆的直径为-->"+round.diameter(temp)+"\n"+
"改圆的周长为-->"+ round.perimeter(temp)+"\n"+
"改圆的面积为-->"+ round.area(temp));
}
}
楼主别忘了给分啊~~~
追问
确定对吗,有运行结果没
追答
没问题的,无语了,你不信运行看下。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |