package com.itheima;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("请选择正方形的边长: ");
int n = in.nextInt();
System.out.print("请输入圆形的半径: ");
int m = in.nextInt();
zhengfanxing(n);
System.out.println("-----------------------------------------");
yuanxing(m);
}
static void zhengfanxing(int m){
for(int i = 1; i <= m; i++)
{
if(i == 1 || i == m)
{
for(int j = 1; j <= m; j++)
System.out.print('*');
System.out.println("");
}
else
{
for(int j = 1; j <= m; j++)
{
if(j == 1 || j == m)
System.out.print('*');
else
System.out.print(' ');
}
System.out.println("");
}
}
}
static void yuanxing(int m){
char[][] a = new char[100][100];
for(int i = 0; i <= 2 * m; i++)
for(int j = 0; j <= 2 * m; j++)
a[i][j] = ' ';
for(int i = 0; i <=2 * m; i++)
for(int j = 0; j <= 2 * m; j++)
if((i - m) * (i - m) + (j - m) * (j - m) == m * m)
a[i][j] = '*';
for(int i = 0; i <= 2 * m; i++)
{
for(int j = 0; j <= 2 * m; j++)
{
System.out.print(a[i][j]);
}
System.out.println("");
}
}
}
java基础案例4-1打印不同的图形
于 2022-02-10 03:07:40 首次发布