//主要代码 System.out.print("长:") double num1=input.nextDouble(); //代码太多以后简写System...("宽:"); double num2=.... System....("高:")double num3=.... System...("表:"+(num1*num2+num1*num3+num2*num3)*2+" 体积:"+n1*n2*n3)//打字不容易求给分
创新互联是专业的南华网站建设公司,南华接单;提供成都做网站、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行南华网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Scanner scanner = new Scanner(System.in);
System.out.println("请输入长方形的长:");
int inputWidth = scanner.nextInt();
System.out.println("请输入长方形的宽:");
int inputHeight = scanner.nextInt();
int area = inputWidth * inputHeight;
int perimeter = 2*(inputWidth+inputHeight);
System.out.println("宽为"+inputWidth+"高为"+inputHeight+"的长方形:");
System.out.println("面积为:"+area);
System.out.println("周长为:"+perimeter);
scanner.close();
class Rectangle{
private int width = 2;
private int length = 1;
public int getWidth(){
return this.width;
}
public void setWidth(int w){
this.width = w;
}
public int getLength(){
return this.length;
}
public void setLength(int l){
this.length = l;
}
public int getArea(){
return this.length * this.width;
}
public int getCircumference(){
return (this.length + this.width) * 2;
}
public Rectangle(){}
public Rectangle(int l, int w){
this.length = l;
this.width = w;
}
}
public class demo{
public static void main(String[] args) {
Rectangle rect = new Rectangle(30, 8);
System.out.print("长方形的面积是:");
System.out.println(rect.getArea());
System.out.printf("长方形的周长是:%d\n", rect.getCircumference());
}
}
//看看我这个程序把 比较符合面向对象的思想,告诉搂住一声,尽量把一些程序写尽方法里,而不是都写在主方法中!这样不好~~~~ 希望对你有用!!
import java.util.Scanner;
public class Ex {
public static int squ(int x,int y){ //求面积的方法
int s = x* y;
return s;
}
public static double len(int x,int y){//求周长的方法
int l = (x+y)*2;
return l;
}
public static void main(String [] aa){
System.out.println("请输入宽:"); //从命令行输入宽
Scanner in = new Scanner(System.in);
int le = in.nextInt();
System.out.println("请输入高:");//从命令行输入高
Scanner in2 = new Scanner(System.in);
int hi = in2.nextInt(); //转换为int型
int mianji = squ(le,hi); //调用方法
System.out.println("面积是:" + mianji);
/*
* 求周长同理,调用周长那个方法即可
*/
}
}