「java面积编程题」求面积的编程
本篇文章给大家谈谈java面积编程题,以及求面积的编程对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java 面积编程题
- 2、JAVA 编程题(输入坐标求出边长和面积以及...)?
- 3、JAVA编程题。编写一个应用程序计算圆的周长和面积,设圆的半径为1.5,输出圆的周长和面积值。
- 4、Java编程求矩形的面积
- 5、JAVA编程中求圆的面积怎么写?
- 6、java编程(11分)求正方形的面积。要求
java 面积编程题
public class Test
{
public static void main(String[] args)
{
Circle c = new Circle("black",5.2);
Rectangle r = new Rectangle("white",2.3,3.5);
System.out.println(c.show());
System.out.println(r.show());
}
}
abstract class Shape
{
String color;
Shape()
{}
Shape(String color)
{
this.color = color;
}
abstract public double getArea();
}
class Circle extends Shape
{
private double r;
Circle(String color,double r)
{
this.color = color;
this.r = r;
}
public double getArea()
{
return Math.PI*Math.pow(r,2);
}
public String show()
{
return "r:" + r + ", color:" + color;
}
}
class Rectangle extends Shape
{
private double a,b;
Rectangle(String color,double a,double b)
{
this.color = color;
this.a = a;
this.b = b;
}
public double getArea()
{
return a*b;
}
public String show()
{
return "a:" + a + " b:" + b +", color:" + color;
}
}
JAVA 编程题(输入坐标求出边长和面积以及...)?
四边形的话,坐标点应该是四对八个坐标数字啊,参数x,y,width,height给出没啥意义啊,题意再说清晰一点
JAVA编程题。编写一个应用程序计算圆的周长和面积,设圆的半径为1.5,输出圆的周长和面积值。
import java.util.Scanner;
public class Circle {
public static void main(String[] args) {
System.out.println("请输入圆半径:");
Scanner input = new Scanner(System.in);
float r = input.nextFloat();
float perimeter = getPerimeter(r);
float area = getArea(r);
System.out.println("圆的周长为:" + perimeter);
System.out.println("圆的面积为:" + area);
}
static float getArea(float r) {
return (float) (3.14 * r * r);
}
static float getPerimeter(float r) {
return (float) (3.14 * r * 2);
}
}
Java编程求矩形的面积
import java.util.*;
public class Rectangle {
private float length; //定义长变量
private float width; // 宽变量
public Rectangle(float length,float width){
this.length=length;
this.width=width;
}
public float getGirth(){
return (length+width)*2;
} //求周长方法
public float getArea(){
return length*width;
} //求面积方法
public static void main (String[] args) {
Scanner in=new Scanner(System.in);//调用输入方法
System.out.println ("请输入矩形的长:");
float a=in.nextFloat();
System.out.println ("请输入矩形的宽:");
float b=in.nextFloat();
System.out.println ("矩形周长为:"+new Rectangle(a,b).getGirth());
System.out.println ("矩形面积为:"+new Rectangle(a,b).getArea());
}
}
JAVA编程中求圆的面积怎么写?
import java.util.Scanner;
//java 并不直接支持控制台输入,但可以使用Scanner类建立它的对象,已读取来System.in的输入
public class KongZhi {
public static void main(String[] args) {
Scanner input = new Scanner( System.in);
System.out.println("Enter a number for radius: ");
double radius = input.nextDouble();
double area= radius*radius*3.14;
System.out.println("The area for the circle of radius "+radius+" "+area);
}
}
扩展资料:
其他方法求圆的面积:
#includestdio.h
#includemath.h
#define M=3.14
int main()
{
int r;
double s;
scanf("%d",r);
s=M*pow(r,2);
printf("%0.7lf",s);
return 0;
}
java编程(11分)求正方形的面积。要求
interface IShape{
public double area();
}
class square implements IShape{
double length ;
public square(double l){
length = l;
}
public double area(){
return length*length;
}
}
public class Test {
public static void main(String[] args) {
square s = new square(5);
System.out.println(s.area());
}
}
java面积编程题的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于求面积的编程、java面积编程题的信息别忘了在本站进行查找喔。
发布于:2022-11-22,除非注明,否则均为
原创文章,转载请注明出处。