java练习题集答案解析 联系客服

发布时间 : 星期日 文章java练习题集答案解析更新完毕开始阅读098bc5c62f3f5727a5e9856a561252d381eb2019

D)false false

5、应用程序的main方法中有以下语句,则输出的结果是 ( A )。 String s1=\ double x=Double.parseDouble(s1); int y=Integer.parseInt(s2); System.out.println(x+y);

A) 12.5 B) 120.5 C) 12 D) “12.5” 三、程序设计题:

按以下要求编写程序 (1) 创建一个Rectangle类,添加width和height两个成员变量 (2) 在Rectangle中添加两种方法分别计算矩形的周长和面积 (3) 编程利用Rectangle输出一个矩形的周长和面积 解答:

public class Rectangle {

float width, height;

public Rectangle(float width, float height) {

this.width = width; this.height = height; }

public float getLength(){

return (this.width + this.height) * 2; }

public float getArea(){

return this.width * this.height; }

public static void main(String [] args) { } }

Rectangle rect = new Rectangle(10, 20);

System.out.println(\周长是:\ System.out.println(\面积是:\