「java输出矩形」java输出矩形*号代码解析

博主:adminadmin 2022-12-04 03:15:07 68

今天给各位分享java输出矩形的知识,其中也会对java输出矩形*号代码解析进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

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

}

}

求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软件打印矩形,行为6行,列为3列,5列,8列?

什么意思是画出一个矩形还是用*输出一个矩形?

import java.io.*;

import java.util.Scanner;

class test

{

public static void main (String[] args)

{

System.out.println("三列矩形");

for (int i = 0; i 6; i++)

{

    printStar(3);

}

System.out.println("五列矩形");

for (int i = 0; i 6; i++)

{

    printStar(5);

}

System.out.println("八列矩形");

for (int i = 0; i 6; i++)

{

    printStar(8);

}

}

public static void printStar(int column)

{

    for(int j = 0; j column; j++)

    {

        System.out.print("* ");

    }

    System.out.println("");

}

}

编写一个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输出矩形的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java输出矩形*号代码解析、java输出矩形的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-04,除非注明,否则均为首码项目网原创文章,转载请注明出处。