Voldemorty
2017-04-16 18:53
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()错误
@Override 把这个标签 干掉!方法前添加这个便签的意义你还没学到,编译器自己会自动生成,但是请你干掉他!
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);
}
}
你这部分代码应该是没问题,我补充了个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);
}
}
Java入门第二季 升级版
530556 学习 · 6091 问题
相似问题