一个简单的java计算问题 javaclass 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我写了一个特别麻烦的,但是我想问下有没有简单的方法。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;} }}} 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)); } } 将长,宽作为属性,将球周长,面积作为方法封装一个矩形Class出来,然后每次传参后,将参数转换为对象,通过对象去调用求周长和面积的方法。楼主看看java中类的概念吧,看完对这个应该就理解了。 你好,你的code我看到了,我想问下可不可以一起输入,然后一起print出来? 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)); } 谢谢。。我已经解开了。。我之前就是不明白,因为我用了同样的方法不知道哪一步错了,就run不了,所以我就认为这个不可行了。呵呵谢谢了! IO操作的小问题,菜鸟求助帖 正则表达式 的问题 怎样判断一个JLable的上方有没有其他组件 问下Java怎么实现输出是一个tree结构。 JAVA学习的人都来帮帮我 一个流用不同方法传输数据会有干扰吗?? 超急高分啊 高分求:itext.jar读取写入文件出错,这个组件好像中文支持不好? 用自己写的类加载器加载类后的问题? 求Java文件发送和接收端原代码,最好是GUI的 用来收发邮件的 JMail类库 可以在JAVA中用吗 怎么调用阿 急!! List<Article> articles = new ArrayList<Article>();出错怎么解决? Java图形编程的一点问题。
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;}
}}}
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));
}
}
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));
}
谢谢。。我已经解开了。。我之前就是不明白,因为我用了同样的方法不知道哪一步错了,就run不了,所以我就认为这个不可行了。呵呵谢谢了!