package demo;
class Ice-cream{
public static void main(String[] args) throws Exception {
//以(x,y)为圆心,显示一个半径为r的圆
int x = 20;
int y = 30;
int r = 15;
//显示空行
for (int i=1; i<(y-r); i++) {
System.out.println();
}
//显示圆的投影
for (int row=(y-r); row<=y; row++) {
StringBuffer line = new StringBuffer();
//计算弦长/2
long temp = Math.round(Math.sqrt((r*r - (y-row)*(y-row))));
//计算当前行的空格
for (int i=0; i<=(x-temp); i++) {
line.append(" ");
}
//计算当前行的**
for (int i=0; i<=(2*temp); i++) {
line.append("**");
}
System.out.println(line);
}
int rowsB = 2*r+1; //指定行数
for (int row=1; row<=rowsB; row++) {
StringBuffer line = new StringBuffer();
//计算当前行的空格
for (int i=1; i<=row+x-r+6; i++) {
line.append(" ");
}
//计算当前行的*
for (int i=1; i<=(2*rowsB-1-2*(row-1)); i++) {
line.append("*");
}
System.out.println(line);
}
}
}
posted on 2009-03-23 09:31
鹏凌 阅读(269)
评论(0) 编辑 收藏 所属分类:
java