TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
命令行打印心形和椭园

椭圆就不给图了.
- import static java.lang.Math.*;
- public class Test{
- public static void main(String args[]){
- print1();
- print2();
-
- }
-
- static void print1(){
- double x,y;
- int H = 3;
-
- for(y = -4;y <= 0;y += 0.3) {
- for(x = -4; x <= 4; x+= 0.2)
- if(abs(Math.sqrt(x*x+y*y) - H*sin(2*atan(y/x))) <= 1
- ||abs(sqrt(x*x+y*y) - H*sin(2*atan(-y/x))) <= 1)
- System.out.printf("*");
- else
- System.out.printf(" ");
- System.out.println();
- }
- for(y=-1;y<=0;y+=0.2){
- for(x=-4;x<=4;x+=0.2)
- if(abs(y)-0.65*x*x>=0.2)
- System.out.printf("*");
- else System.out.printf(" ");
- System.out.println();
- }
- }
- static void print2(){
- int a,b;
- double x,y;
- a = 5;
- b= 8;
-
- for(y = 0; y <= 4*a; y++){
- for(x = 0; x <= 2*b; x++){
- if((x-a)*(x-a)/(a*a) + (y-b)*(y-b)/(b*b)< 1)
- System.out.printf("*");
- else
- System.out.printf(" ");
- }
- System.out.println();
- }
- }
- }
复制代码 |
|