解决方案 »

  1.   

    我写了一个特别麻烦的,但是我想问下有没有简单的方法。import java.util.Scanner;public class rectangle{public static double getarea(double length, double width){
    return length*width;
    }
    public static double getarea1(double length1, double width1){
    return length1*width1;
    }
    public static double getarea2(double length2, double width2){
    return length2*width2;
    }
    public static double getperimeter(double length, double width){
    return 2*length+2*width;
    }
    public static double getperimeter1(double length1, double width1){
    return 2*length1+2*width1;
    }
    public static double getperimeter2(double length2, double width2){
    return 2*length2+2*width2;
    } public static void main(String[]args){
    Scanner input = new Scanner(System.in); System.out.println("Please enter rectangle1's length: ");
    double length=input.nextDouble(); System.out.println("Please enter rectangle1's width: ");
    double width=input.nextDouble(); System.out.println("Please enter rectangle2's length: ");
    double length1=input.nextDouble(); System.out.println("Please enter rectangle2's width: ");
    double width1=input.nextDouble(); System.out.println("Please enter rectangle3's length: ");
    double length2=input.nextDouble(); System.out.println("Please enter rectangle3's width: ");
    double width2=input.nextDouble();
    while(length != 0 ){
    if (length==length){
    System.out.println("The rectangle1's area is: "+getarea(length, width)+", perimeter is: "+getperimeter(length,width));
    }
    if (length==length){
    System.out.println("The rectangle2's area is: "+getarea1(length1, width1)+", perimeter is: "+getperimeter1(length1,width1));
    }
    if (length==length){
    System.out.println("The rectangle3's area is: "+getarea2(length2, width2)+", perimeter is: "+getperimeter2(length2,width2));
    break;}
    }}}
      

  2.   


        public static double getarea(double length, double width) {
            return length * width;
        }    public static double getperimeter(double length, double width) {
            return (length + width) * 2;
        }    public static void main(String[] args) {
            for (int i = 0; i < 3; i++) {
                System.out.println("输入第" + (i + 1) + "个矩形的长和宽:");
                Scanner input = new Scanner(System.in);
                double length = input.nextDouble();
                double width = input.nextDouble();
                System.out.println("面积:" + getarea(length, width));
                System.out.println("周长:" + getperimeter(length, width));
            }
        }
      

  3.   

    将长,宽作为属性,将球周长,面积作为方法封装一个矩形Class出来,然后每次传参后,将参数转换为对象,通过对象去调用求周长和面积的方法。楼主看看java中类的概念吧,看完对这个应该就理解了。
      

  4.   

    你好,你的code我看到了,我想问下可不可以一起输入,然后一起print出来?
      

  5.   


        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            double length1 = input.nextDouble();
            double width1 = input.nextDouble();
            double length2 = input.nextDouble();
            double width2 = input.nextDouble();
            double length3 = input.nextDouble();
            double width3 = input.nextDouble();
            System.out.println("1面积:" + getarea(length1, width1));
            System.out.println("1周长:" + getperimeter(length1, width1));
            System.out.println("2面积:" + getarea(length2, width2));
            System.out.println("2周长:" + getperimeter(length2, width2));
            System.out.println("3面积:" + getarea(length3, width3));
            System.out.println("3周长:" + getperimeter(length3, width3));
        }
      

  6.   


    谢谢。。我已经解开了。。我之前就是不明白,因为我用了同样的方法不知道哪一步错了,就run不了,所以我就认为这个不可行了。呵呵谢谢了!