求一个简单java程序代码,谢谢public class TestStar {
public static void main(String[] args) {
String star = "*";
for (int i = 0; i5; i) {
if (i == 0) {
System.out.print(" "star);
System.out.println();
}
if (i == 1) {
for (int z = 0; z4; z) {
System.out.print(" "star);
}
System.out.println();
}
if (i == 2) {
System.out.print(" ");
for (int x = 0; x3; x) {
System.out.print(" "star);
}
System.out.println();
}
if (i == 3) {
for (int y = 0; y2; y) {
System.out.print(" "star" ");
}
}
}
}
}
是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给你写一个)
求JAVA大佬/**
* @author 徒有琴 扣:574549426
*/
class Test{
public static void main(String[] args) {
Stuff[]stuffs=new Stuff[10];
for (int i = 0; istuffs.length; i) {
if(i%2==0){
stuffs[i]=new Book("book" i,"press" i);
}else{
stuffs[i]=new Cloth("Nick" i,"Color" i);
}
}
Bag luggage=new Luggage(5);
Bag schoolBag=new SchoolBag(5);
for (int i = 0; istuffs.length; i) {
luggage.putStuff(stuffs[i]);
schoolBag.putStuff(stuffs[i]);
}
luggage.printAllStuffs();
schoolBag.printAllStuffs();
}
}
public class Bag {
Stuff[] stuffs;
int size;
int currentSize;
public Bag(int size) {
this.size = size;
this.currentSize = 0;
this.stuffs = new Stuff[size];
}
void putStuff(Stuff stuff) {
if (currentSize = size) {
System.out.println("满了");
return;
}
stuffs[currentSize] = stuff;
currentSize;
}
Stuff getStuff(int index) {
if (index = currentSize) {
System.out.println("没有");
return null;
}
return stuffs[index];
}
void printAllStuffs() {
for (Stuff stuff : stuffs) {
System.out.println(stuff);
}
}
}
class Luggage extends Bag {
public Luggage(int size) {
super(size);
}
}
class SchoolBag extends Bag {
public SchoolBag(int size) {
super(size);
}
}
class Stuff {
}
class Book extends Stuff {
String bookName;
String press;
public Book(String bookName, String press) {
this.bookName = bookName;
this.press = press;
}
@Override
public String toString() {
return "Book{"
"bookName='"bookName'\''
", press='"press'\''
'}';
}
}
class Cloth extends Stuff {
String brand;
String color;
public Cloth(String brand, String color) {
this.brand = brand;
this.color = color;
}
@Override
public String toString() {
return "Cloth{"
"brand='"brand'\''
", color='"color'\''
'}';
}
}
用java 在窗体中画一个简单图形 。帮你改了一下 。
你要画在panel上,然后frame.add(panel)就能显示 。
是不是和applet搞混了,applet复写一些方法就能显示,但现在你编的是java gui
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*; //import javax.swing.Timer;
import java.awt.BasicStroke;
//import java.util.Date;
//import java.text.*;
//import java.util.*;
public class TestGui {
public void paint(Graphics g) {
Graphics2D a2d = (Graphics2D) g;
int x = 120, y = 90, width = 150, height = 150;
a2d.setColor(Color.red);
a2d.setStroke(new BasicStroke(3.0f)); // 设置线条宽度,3.0即线的宽度
a2d.drawOval(x, y, width, height);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
// frame.add(new paint(),BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocation(200, 200);
frame.setVisible(true);
Panel p = new Panel();
frame.add(p);
// frame.paint(null);
// TODO code application logic here
}
}
class Panel extends JPanel {
// 重新覆盖paint方法
public void paint(Graphics g) {
super.paint(g);
Graphics2D a2d = (Graphics2D) g;
int x = 120, y = 90, width = 150, height = 150;
a2d.setColor(Color.red);
a2d.setStroke(new BasicStroke(3.0f)); // 设置线条宽度,3.0即线的宽度
a2d.drawOval(x, y, width, height);
}
}
【java代码画书包 java编写一个简单的画板程序】关于java代码画书包和java编写一个简单的画板程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- oracle11g自动表分区,oracle 表分区
- 日本云服务器价格多少钱,日本云服务器vnc
- 直播打光技巧女生,直播打光灯安装图片
- go语言json解析 go struct json
- 大文件怎么复制到u盘失败,大文件不能复制到u盘
- 经营战争游戏电脑,经营战争策略游戏单机
- 直播伴侣总是显示投屏异常,直播伴侣投屏创建素材失败
- vb.net打印换页 vb中打印窗体怎么居中
- 做一个家庭住址的js选择框,家庭地址的正则表达式