想在练习题中添加Scanner方便输入,没有报错但什么也执行不出来
还有怎样在多个子类中添加scanner
还有怎样在多个子类中添加scanner
2016-09-26
import java.util.Scanner;
public class Rectangle extends Shape{
public Rectangle(){//无参构造函数
a = 0;
b = 0;
}
public Rectangle(int a,int b){//有参构造函数
this.a = a;
this.b = b;
}
public void area(){
int area = a*b;
System.out.println("矩形面积area:"+area);
}
public void cm(){
int cm = (a+b)*2;
System.out.println("矩形周长cm:"+cm);
}
public static void main(String[] args) {
System.out.println("请输入长:");
Scanner input = new Scanner(System.in);
int temp1 = input.nextInt();
System.out.println("请输入宽:");
int temp2 = input.nextInt();
Rectangle R1 = new Rectangle(temp1,temp2);
R1.area();
R1.cm();
}
}
举报