importjava.util.Scanner;publicclassTest4{privatestaticdoublewidth;privatestaticdoublelength;privateStringperimeter;privateStringarea;//privateTest4(){}//privatevoidTest4(...
import java.util.Scanner;
public class Test4{
private static double width;
private static double length;
private String perimeter;
private String area;
//
private Test4(){}
//
private void Test4(double width,double length){
this.width=width;
this.length=length;}
//set get
public void setwidth(double width){
this.width=width;}
public void setlength(double length){
this.length=length;}
public double getwidth(){
return this.width;}
public double getlength(){
return this.length;}
//
public double getperimeter(){
return (width+length)*2;}
public double getarea(){
return width*length;}
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入长方形的长");
length = sc.nextInt();
System.out.println("请输入长方形的宽");
width = sc.nextInt();
System.out.println("长方形的周长是:"+sc.perimeter()+"长方形的面积是:"+sc.area());
}
}
为什么输出不了?难道sc.perimeter()这样的格式不对吗?
展开