问答详情
源自:10-3 Java 中的抽象类

求大神看看这个错误在哪

public void Area() {

// TODO Auto-generated method stub

Scanner a = new Scanner(System.in);

int w = a.nextInt();

Scanner b = new Scanner(System.in);

int l = b.nextInt();

double area = w*l;

System.out.println(area);

}

@Override

public void Cir() {

// TODO Auto-generated method stub

Scanner a = new Scanner(System.in);

int w = a.nextInt();

Scanner b = new Scanner(System.in);

int l = b.nextInt();

int cir = 2*(w+l);

System.out.println(cir);


}

为什么一直显示public void Area() 和public void Cir()错误

提问者:Voldemorty 2017-04-16 18:53

个回答

  • 没了哆啦A梦的大熊
    2017-04-29 17:11:17

    @Override 把这个标签 干掉!方法前添加这个便签的意义你还没学到,编译器自己会自动生成,但是请你干掉他!

  • 慕粉163300228
    2017-04-16 20:41:53

    import java.util.Scanner;


    public class Demo1 {

    public void Area() {

    // TODO Auto-generated method stub

    Scanner a = new Scanner(System.in);

    int w = a.nextInt();

    Scanner b = new Scanner(System.in);

    int l = b.nextInt();

    double area = w*l;

    System.out.println(area);

    }

    public void Cir() {

    Scanner a = new Scanner(System.in);

    int w = a.nextInt();

    Scanner b = new Scanner(System.in);

    int l = b.nextInt();

    int cir = 2*(w+l);

    System.out.println(cir);


    }

    }


  • 慕桂英9156406
    2017-04-16 20:41:20

    你这部分代码应该是没问题,我补充了个main,执行了一下,可以执行,完整代码:

    //包名

    package com.practice;

    //导入Scanner

    import java.util.Scanner;


    public class HellWorld {

    public static void main(String[] args) {

    // TODO Auto-generated method stub

            HellWorld  rec1 = new HellWorld();

            rec1.Area();

            rec1.Cir();

    }

    public void Area() {

    // TODO Auto-generated method stub

    Scanner a = new Scanner(System.in);

    int w = a.nextInt();

    Scanner b = new Scanner(System.in);

    int l = b.nextInt();

    double area = w*l;

    System.out.println(area);

    }

    //@Override

    public void Cir() {

    // TODO Auto-generated method stub

    Scanner a = new Scanner(System.in);

    int w = a.nextInt();

    Scanner b = new Scanner(System.in);

    int l = b.nextInt();

    int cir = 2*(w+l);

    System.out.println(cir);

    }

    }