真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java實心矩形代碼 java編程實現(xiàn)矩形類

JAVA,寫一個名為Rectangle的類表示矩形

這個我做完了 希望您能滿意

成都創(chuàng)新互聯(lián)公司是少有的網(wǎng)站設(shè)計、網(wǎng)站制作、營銷型企業(yè)網(wǎng)站、小程序開發(fā)、手機APP,開發(fā)、制作、設(shè)計、買鏈接、推廣優(yōu)化一站式服務(wù)網(wǎng)絡(luò)公司,自2013年起,堅持透明化,價格低,無套路經(jīng)營理念。讓網(wǎng)頁驚喜每一位訪客多年來深受用戶好評

public class Rectangle {

private double height;

private double width;

private String color;

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;

}

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public Rectangle(double width,double height,String color){

this.setColor(color);

this.setHeight(height);

this.setWidth(width);

}

public void getArea(){

double area=0;

area=this.height*this.width;

System.out.println("矩形的面積為"+area);

}

public String toString(){

String recStr="矩形的高度:"+this.getHeight()+"寬度:"+this.getWidth()

+"顏色:"+this.getColor();

return recStr;

}

/**

* 測試函數(shù)

* @param args

*/

public static void main(String[] args) {

Rectangle rec=new Rectangle(3, 4, "紅色");

rec.getArea();

System.out.println(rec.toString());

}

}

java中做一個按鈕,點擊按鈕后畫一個矩形的代碼怎么寫?

兄弟幫你寫了一個:

import java.awt.Button;

import java.awt.Color;

import java.awt.Frame;

import java.awt.Graphics;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.util.Random;

public class Print {

public static void main(String[] args) {

new Te();

}

}

class Te extends Frame implements ActionListener {

Color cc = Color.red;

int x = -20, y = -50;

Random r = new Random();

public Te() {

this.setLayout(null);

Button b = new Button("畫圓");

this.add(b);

b.setBounds(30,30,50,50);

b.addActionListener(this);

this.addWindowListener(new WindowAdapter () {

@Override

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

this.setBounds(200,200,500,400);

this.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

this.cc = Color.red;

this.x = r.nextInt(400);

do {

int x1 = r.nextInt(300);

this.y = x1;

} while (this.y 50);

this.repaint();

}

@Override

public void paint(Graphics g) {

Color c = g.getColor();

g.setColor(cc);

g.drawRect(x,y,50,50);

g.setColor(c);

}

}

JAVA輸入長和寬打印實心矩形。要簡單點的方法。打印結(jié)果大概是 ****** ****** ******

Scanner sc = new Scanner(System.in);

int length = sc.nextInt();

int width = sc.nextInt();

for(int i = 0; i length; i++){

for(int j = 0; j width; j++){

System.out.print("*");

}

System.out.println();

}


文章題目:java實心矩形代碼 java編程實現(xiàn)矩形類
分享網(wǎng)址:http://weahome.cn/article/ddogiid.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部