13个回答
展开全部
以下是用类,方法和构造函数来实现的,希望对你有帮助。
里面的变量你可以根据自己实际来填写就可以运行了。
public class Circle
{
public int x;
public int y;
public int radius;
public double area()
{
double theArea;
theArea = 3.14159 * radius * radius;
return theArea;
}
public double circumference()
{
double theCirc;
theCirc = 2 * 3.14159 * radius;
return theCirc;
}
public Circle()
{
x = 5;
y = 5;
radius = 1;
}
public void print_circle_info()
{
Console.WriteLine("\nCircle:Center=({0},{1})",x,y);
Console.WriteLine(" Radius={0}",radius);
Console.WriteLine(" Area={0}",area());
Console.WriteLine(" Circum={0}",circumference());
}
}
class Program
{
static void Main(string[] args)
{
Circle first = new Circle();
Circle second = new Circle();
first.x = 10;
first.y = 14;
first.radius = 3;
first.print_circle_info();
second.print_circle_info();
Console.ReadKey();
}
}
里面的变量你可以根据自己实际来填写就可以运行了。
public class Circle
{
public int x;
public int y;
public int radius;
public double area()
{
double theArea;
theArea = 3.14159 * radius * radius;
return theArea;
}
public double circumference()
{
double theCirc;
theCirc = 2 * 3.14159 * radius;
return theCirc;
}
public Circle()
{
x = 5;
y = 5;
radius = 1;
}
public void print_circle_info()
{
Console.WriteLine("\nCircle:Center=({0},{1})",x,y);
Console.WriteLine(" Radius={0}",radius);
Console.WriteLine(" Area={0}",area());
Console.WriteLine(" Circum={0}",circumference());
}
}
class Program
{
static void Main(string[] args)
{
Circle first = new Circle();
Circle second = new Circle();
first.x = 10;
first.y = 14;
first.radius = 3;
first.print_circle_info();
second.print_circle_info();
Console.ReadKey();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.io.*;
public class Circle {
public static double PI=3.14;
double radius,area,diameter;
public double getRadius(double x)
{
radius = x;
return radius;
}
public double CalDiameter(double x)
{
diameter = 2*x;
return diameter;
}
public double CalArea(double x)
{
area=PI*x*x;
return area;
}
public static void main(String args[])
{
double x;
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入圆的半径长度:");
String str =in.readLine();
x=Double.valueOf(str).doubleValue();
}
catch (Exception e)
{
System.out.println("您的输入有错!");
return;
}
Circle myCircle;
myCircle=new Circle();
System.out.println("圆的半径,直径,面积分别是:"+myCircle.getRadius(x)+" "+myCircle.CalDiameter(x)+" "+myCircle.CalArea(x));
}
}
大二刚学java写的,直接复制过来了,希望有用,哈哈
public class Circle {
public static double PI=3.14;
double radius,area,diameter;
public double getRadius(double x)
{
radius = x;
return radius;
}
public double CalDiameter(double x)
{
diameter = 2*x;
return diameter;
}
public double CalArea(double x)
{
area=PI*x*x;
return area;
}
public static void main(String args[])
{
double x;
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入圆的半径长度:");
String str =in.readLine();
x=Double.valueOf(str).doubleValue();
}
catch (Exception e)
{
System.out.println("您的输入有错!");
return;
}
Circle myCircle;
myCircle=new Circle();
System.out.println("圆的半径,直径,面积分别是:"+myCircle.getRadius(x)+" "+myCircle.CalDiameter(x)+" "+myCircle.CalArea(x));
}
}
大二刚学java写的,直接复制过来了,希望有用,哈哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Scanner是Java的,都给C的干嘛
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
什么程序?C或者C++?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用什么语言编写
追问
要求输入、就要用到Scanner那个了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询