导航:首页 > 编程语言 > rectanglejava

rectanglejava

发布时间:2025-03-08 17:51:26

1. java编程 求矩形周长和面积

import java.util.*;
public class Rectangle {

private float length; //定义长变量
private float width; // 宽变量
public Rectangle(float length,float width){
this.length=length;
this.width=width;
}
public float getGirth(){
return (length+width)*2;

} //求周长方法

public float getArea(){
return length*width;
} //求面积方法
public static void main (String[] args) {
Scanner in=new Scanner(System.in);//调用输入方法

System.out.println ("请输入矩形的长:");
float a=in.nextFloat();
System.out.println ("请输入矩形的宽:");
float b=in.nextFloat();
System.out.println ("矩形周长为:"+new Rectangle(a,b).getGirth());
System.out.println ("矩形面积为:"+new Rectangle(a,b).getArea());

}

}
//Jcreator4.0编译通过,写的比较简单 只有简单的功能 刚刚写的求周长时忘乘2了...

2. Java编写一个矩形类,并计算面积和周长

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());
}
}

3. java怎么算长宽

根据要求,步骤设计分别如下:

1、创建项目【Ex2_1】:

(3)rectanglejava扩展阅读:

1、System.out.println解析。

System是一个类,继承自根类Object。out是类PrintStream类实例化的一个对象,且是System类的静态成员变量,println()是类PrintStream的成员方法,被对象out调用。

2、Scanner input=new Scanner(System.in)。

Scanner是一个类,是一个开源代码,用他创建一个对象(input),System.in可以看做一个参数,这个参数是键盘输入内容。

对象(input)有许多的方法如:input.next();指的是键盘输入的文字内容,在用String a来接收就是:String a=input.next()。

阅读全文

与rectanglejava相关的资料

热点内容
股票涨跌源码怎么看 浏览:575
加密软件做法 浏览:54
美国程序员有多少中国人 浏览:739
人民日报app里怎么看新闻早班车 浏览:584
忘了app怎么办 浏览:528
如何用云服务器做云平台 浏览:298
非箍筋加密区剪力 浏览:116
利联科技服务器卡怎么办 浏览:383
js和python哪个好 浏览:460
c盘的哪些文件夹没用 浏览:80
文件为什么会超出在线解压限制 浏览:588
python类实例化对象 浏览:794
硬盘dos外部命令 浏览:792
做算法还是开发 浏览:872
按键精灵自定义图层命令 浏览:353
魅蓝3手机音视频文件夹 浏览:945
安卓手机制表怎么换行 浏览:215
墙柱搭接箍筋怎么加密 浏览:456
怎么加密不让人打开 浏览:336
2g3g算法 浏览:206