关于JAVA打印星星的问题

[复制链接]
查看11 | 回复1 | 2010-9-18 19:01:32 | 显示全部楼层 |阅读模式
我写了一段代码
import javax.swing.*;
public class Diamond{
public void showStar(){

String s1=JOptionPane.showInputDialog("请输入一个数");

int n=Integer.parseInt(s1);

int a,b,c;

if(n%2==1)

{ for(a=1;a<=4;a++){

for(b=1;b<=4-a;b++){System.out.print(" ");}

for(c=1;c<=2*a-1;c++){System.out.print("*");}

System.out.println();

}

for(a=1;a<=3;a++){

for(b=1;b<=a;b++){System.out.print(" ");}

for(c=1;c<=7-2*a;c++){System.out.print("*");}

System.out.println();

}

}

else{

for(a=1;a<=6;a++){

for(b=1;b<=6-a;b++){System.out.print(" ");}

for(c=1;c<=a;c++){System.out.print("* ");}

System.out.println();

}

for(a=1;a<=5;a++){

for(b=1;b<=a;b++){System.out.print(" ");}

for(c=1;c<=6-a;c++){System.out.print("* ");}

System.out.println();

}

}

}
public class Star{


public static void main (String[] args ){



Diamond d = new Diamond();



d.showStar();
}
}
}

运行的时候出错了,不知道是哪个地方错了,希望高手能够帮我找出来,在线等,先谢谢啦

回复

使用道具 举报

千问 | 2010-9-18 19:01:32 | 显示全部楼层
public class Star{这一行删除倒数第二个中括号删除
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行