资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java程序求矩形代码,编写一个求矩形面积的c语言程序

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

class Rectangle{

创新互联主营十堰网站建设的网络公司,主营网站建设方案,app开发定制,十堰h5小程序定制开发搭建,十堰网站营销推广欢迎十堰等地区企业咨询

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

}

}

编写一个JAVA程序,描写一个矩形类,并输出某个矩形的长,宽,面积。具体描述如下?

// 矩形

public class RectangleDemo {

public static void main(String[] args) {

RectangleDemo demo = new RectangleDemo(12, 32);

System.out.println(demo.getPerimeter());

System.out.println(demo.getArea());

demo = new RectangleDemo();

System.out.println(demo.getArea());

System.out.println(demo.getPerimeter());

demo.setHeight(50);

demo.setWidth(30);

System.out.println(demo.getArea());

System.out.println(demo.getPerimeter());

}

// 求周

public double getPerimeter() {

return (height + width) * 2;

}

// 求面积

public double getArea() {

return height * width;

}

public RectangleDemo(double height, double width) {

this.height = height;

this.width = width;

}

public RectangleDemo() {

this.height = 10;

this.width = 10;

}

private double height;// 高度

private double width;// 宽度

public double getHeight() {

return height;

}

public void setHeight(double height) {

this.height = height;

}

public double getWidth() {

return width;

}

public void setWidth(double width) {

this.width = width;

}

}

编写矩形类RectangleJava程序矩形类两数据员别rLength宽rWidth通getLength()、getWidth()、getArea()别查看矩形、宽面积通setLength()setWidth()重新设置矩形宽

求java 输出正方形(用*号)的代码!

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("请输入正方形的大小:");

int line = s.nextInt();; // 正方形的边长

for (int i = 1; i = line; i++) { // 行

for (int j = 1; j = line; j++) { // 列

if (i == 1 || i == line) { // 如果是第一行或者是最后一行则输出星号

System.out.print("* ");

} else if (j == 1 || j == line) { // 如果是第一列或者是最后一列则输出星号

System.out.print("* ");

} else {

System.out.print(" "); // 如果不是第一行、最后一行、第一列、最后一列则输出空格

}

}

System.out.print("\n"); // 换行

}

}

Java编写一个矩形类,至少包含以下方法:

import java.awt.Point;

public class Rectangle {

private int widthT = 0;

private int heightT = 0;

Point point = new Point();

public Rectangle(int width, int height, int centerX, int centerY) {

widthT = width;

heightT = height;

point.x = centerX;

point.y = centerY;

}

public int width() {

return widthT;

}

public int height() {

return heightT;

}

public int centerX() {

return point.x;

}

public int centerY() {

return point.y;

}

}

麻烦采纳呦~~~亲


本文标题:java程序求矩形代码,编写一个求矩形面积的c语言程序
文章源于:http://cdkjz.cn/article/dsgssde.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220