
正文
java矩形的代码 java矩形类的定义和调用
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
急求java矩形九九乘法表代码,是矩形,不是梯形,谢谢。
public class TestBaiduKnow {
public static void main(String[] args) {
for (int i = 0; i = 9; i++) {
for (int j = 0; j = 9; j++) {
System.out.print(i + " * " + j + " = " + i * j + "\t");
}
System.out.println();
}
}
}
相关问答
Q1: 编写一个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()重新设置矩形宽
Q2: 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 ("请输入矩形的长java矩形的代码:");
float a=in.nextFloat();
System.out.println ("请输入矩形的宽java矩形的代码:");
float b=in.nextFloat();
System.out.println ("矩形周长为java矩形的代码:"+new Rectangle(a,b).getGirth());
System.out.println ("矩形面积为:"+new Rectangle(a,b).getArea());
}
}
Q3: 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);
}
}
Q4: java 画矩形
java矩形的代码你的代码有问题java矩形的代码,你的类本身是framejava矩形的代码,你也在类中绘制,但是你却没有显示,而是另外定义java矩形的代码了一个frame来显示,你修改一下java矩形的代码:
import java.awt.Color;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Rectangle;
public class FrameTest extends Frame {
/**
* @param args
*/
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.black);
g.fillRect(100, 100, 30, 30);
try {
Thread.sleep(500);
}
catch (Exception ex) {
ex.printStackTrace();
}
//repaint();
}
FrameTest()
{
super("title");
setLocation(100,100);
setSize(600,400);
setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FrameTest ft=new FrameTest();
}
}
这样应该没问题了。
java矩形的代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java矩形类的定义和调用、java矩形的代码的信息别忘了在本站进行查找喔。






