package lilsheeeep;
import java.util.Scanner;
import java.text.DecimalFormat;
public class RegularPolygon {
private int sides;
private double length;
public RegularPolygon(){
}
public RegularPolygon(int n,double m) {
sides = n;
length = m;
}
public void getarea() {
double x = sides*length*length/4*Math.tan(Math.PI/sides);
String s = String.format("%.4f",x);
System.out.println("边长为"+length+"的正"+sides+"边形的面积是"+s);
}
public void getPerimeter() {
double x = sides * length;
String s = String.format("%.4f",x);
System.out.println("边长为"+length+"的正"+sides+"边形的边长是"+s);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
double b = scan.nextDouble();
RegularPolygon rtt = new RegularPolygon(a,b);
rtt.getarea();
rtt.getPerimeter();
}
}
这是我写的一个代码,如果不用scanner输入赋值,用构造函数直接赋值,则正常运行,使用scanner之后就不出控制台,没任何反应,它也不报错。