java 控制台 画圆
//实心圆
import java.util.Scanner;
class circle
{
public static void main(String[] args)
{
new circle().print();
}
//画圆函数
void print() {
System.out.println("输入半径:");
Scanner input=new Scanner(System.in);
int r=input.nextInt();
System.out.println("输出:");
for(int y=0; y<=2*r;y+=2){
int x=(int)Math.round(r-Math.sqrt(r*r-(r-y)*(r-y)));
int l=2*(r-x);
for(int i=0;i<=x;i++){
System.out.print(" ");
}
System.out.print(".");
for(int i=0;i<=l;i++){
System.out.print("*");
}
System.out.println("*");
}
}
}
//空心圆
import java.util.Scanner;
class circle2
{
public static void main(String[] args)
{
new circle2().print();
}
//画圆函数
void print() {
System.out.println("输入半径:");
Scanner input=new Scanner(System.in);
int r=input.nextInt();
System.out.println("输出:");
for(int y=0; y<=2*r;y+=2){
int x=(int)Math.round(r-Math.sqrt(r*r-(r-y)*(r-y)));
int l=2*(r-x);
for(int i=0;i<=x;i++){
System.out.print(" ");
}
System.out.print("*");
for(int i=0;i<=l;i++){
System.out.print("*");
}
System.out.println("");
}
}
}
鲜花会生锈,盐巴会腐烂