编写applet程序,打印下面的菱形形状。最大限度地利用循环结构,并最大限度地减少输出语句。
*
***
*****
*******
*********
*******
*****
***
*
*
***
*****
*******
*********
*******
*****
***
*
解决方案 »
- spring注入dao单例问题
- 关于File类的一个小问题
- java设计实现日历计算程序
- 求一myeclipse6.5下反编译工具
- class or interface expected
- Jboss里怎么加入CA认证?
- 请问哪里有jive的电子书籍下载?
- [超级技术问题] 问一个关于永中Office的编译问题?
- 谁用过sun.net.smtp.SmtpClient来发过mail啊,本人只是想发邮件而已,并不想登录,100分相送
- 请问Jbuilder 6.0 可不可以安装在redhatlinux 7.2 里?该如何安装?谢谢!
- 如何用JAVA做一个客户端程序,没隔几分钟就检查数据库是否有新记录。如果有就通知相关人员有新的短消息。
- 求一个提取${...}中内容的正则表达式
String prit = "*";
int max = 19;
int col = max;
int step = 2;
for (int starts = 1,row=1;row<= max;starts++) {
if(starts<(col/2)+1||starts>(max-(col/2))){
System.out.print(" ");
}else{
System.out.print(prit);
}
if(starts==max){
col = col-step;
starts = 0;
step = ((++row!=(max/2+1))?step:-step);
System.out.println();
}
}
但是我这个题目是做applet程序的啊`~不是应用程序。
private int max = 19;
private int col = max;
private int step = 2;
public void paint(Graphics g) {
int xpos =100;
int ypos =100;
for (int starts = 1,row=1;row<= max;starts++) {
if(starts<(col/2)+1||starts>(max-(col/2))){
//System.out.print(" ");
xpos = xpos+5;
}else{
//System.out.print(prit);
g.drawString(prit,xpos,ypos);
xpos = xpos+5;
}
if(starts==max){
col = col-step;
starts = 0;
step = ((++row!=(max/2+1))?step:-step);
//System.out.println();
ypos =ypos+10;
xpos =100;
}
}
}