提示在类中找不到 main 方法!!!!

代码如下: class AreaAndLength{
double sideA,sideB,sideC,area,length;
boolean b;
public AreaAndLength(double a,double b,double c){
sideA=a;
sideB=b;
sideC=c;
if(a+b>c)
{
this.b=true;
}
else{
this.b=false;
}
}
double getLength(){
return sideA+sideB+sideC;
}
public double getArea(){
if(b){
double p=(sideA+sideB+sideC)/2.0;
area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC));
return area;
}
else{
System.out.println("不是一个三角形,不能计算面积");
return 0;
}
}
}
class Rectangle{
double width,height,area;
Rectangle(double w,double h){
width=w;
height=h;
}
double getLength(){
return (width+height)*2;
}
double getArea(){
return width*height;
}
}
class Circle{
double radius,area;
Circle(double r){
radius=r;
}
double getLength(){
return 6.18*radius;
}
double getArea(){
return 3.14*radius*radius;
}
}
class AreaAndLength{
double length,area;
Circle circle=null;
AreaAndLength trangle=null;
Rectangle rectangle=null;
Circle cicle=new Circle(6.0);
AreaAndLength trangle=new AreaAndLength(3.0,2.0,2.0);
Rectangle rectangle=new Rectangle(3.0,5.0);
public static void main(String[] args){

length=circle.getLength();
System.out.println("圆的周长:"+length);
area=circle.getArea();
System.out.println("圆的面积:"+area);
length=trangle.getLength();
System.out.println("三角形的周长:"+length);
area=trangle.getArea();
System.out.println("三角形的面积:"+area);
area=rectangle.getArea();
System.out.println("矩形的面积:"+area);
length=rectangle.getLength();
System.out.println("矩形的周长:"+length);
}
}

/*出現"提示在类中找不到 main方法"的原因是:創建對象的位置不對,應該在主方法內去創建*/
public class Demo {
static double length, area;
public static void main(String[] args) {
Circle circle = new Circle(6.0);//圓
AreaAndLength aal=new AreaAndLength(2,3,3);//三角形
Rectangle re=new Rectangle(5,3);//矩形

    length = circle.getLength();
    System.out.println("圆的周长:" + length);//37.08
    area = circle.getArea();
    System.out.println("圆的面积:" + area);
    length = aal.getLength();
    System.out.println("三角形的周长:" + length);
    area = aal.getArea();
    System.out.println("三角形的面积:" + area);
    area = re.getArea();
    System.out.println("矩形的面积:" + area);
    length = re.getLength();
    System.out.println("矩形的周长:" + length);
}

}
class AreaAndLength {
double sideA, sideB, sideC, area, length;
boolean b;

public AreaAndLength(double a, double b, double c) {
    sideA = a;
    sideB = b;
    sideC = c;
    if (a + b > c) {
        this.b = true;
    } else {
        this.b = false;
    }
}

double getLength() {
    return sideA + sideB + sideC;
}

public double getArea() {
    if (b) {
        double p = (sideA + sideB + sideC) / 2.0;
        area = Math.sqrt(p * (p - sideA) * (p - sideB) * (p - sideC));
        return area;
    } else {
        System.out.println("不是一个三角形,不能计算面积");
        return 0;
    }
}

}
class Rectangle {
double width, height, area;

Rectangle(double w, double h) {
    width = w;
    height = h;
}
/*矩形面積的周長方法*/
double getLength() {
    return (width + height)*2;
}
/*矩形面積的方法*/
double getArea() {
    return width*height;
}

}
class Circle {
double radius, area;

 Circle(double r) {
    radius = r;
}
 /*圓的周長方法*/
double getLength() {
    return 6.18 * radius;
}
/*圓的面積方法*/
double getArea() {
    return 3.14 * radius * radius;
}

}

你是没写main函数吧?

AreaAndLength这个类怎么有两个, 还有就是你所有的类写在一个类中的么

main 函数的类必须是public的,而且类名和文件名称必须一致

。。。你从哪个类运行程序,就必须有而且只能有一个main方法,要不然程序从哪开始执行

AreaAndLength trangle=null;
Rectangle rectangle=null;
Circle cicle=new Circle(6.0);
AreaAndLength trangle=new AreaAndLength(3.0,2.0,2.0);
Rectangle rectangle=new Rectangle(3.0,5.0);
trangle,rectangle这两个变量也重了, 可改为:
AreaAndLength trangle=null;
Rectangle rectangle=null;
Circle cicle=new Circle(6.0);
trangle=new AreaAndLength(3.0,2.0,2.0);
rectangle=new Rectangle(3.0,5.0);

要么 在别的类里面 调用这个类,这么在这个类里面写个main方法,然后调用你自己的初始化方法

看你的括号。对应好了没有。

要么 在别的类里面 调用这个类,这么在这个类里面写个main方法,然后调用你自己的初始化方法

你把main函数写到第一个类里面去了

在Java中,main()方法是Java应用程序的入口方法,也就是说,程序在运行的时候,第一个执行的方法就是main()方法,这个方法和其他的方法有很大的不同,比如方法的名字必须是main,方法必须是public static void 类型的,方法必须接收一个字符串数组的参数等等。
给你一个简单的例子:
**

  • Java中的main()方法详解 */ public class HelloWorld { public static void main(String args[]) { System.out.println("Hello World!"); } }

你把main函数写到一个类里面去了

谢谢回答!!我自己写错了 = = 抱歉!!!