利用java语言编写程序显示图案“java”

public class Demo5 {
    //点坐标
    public static class point
    {
        
        public int x;
        public int y;
        public point(int ix,int iy)
        {
            x=ix;
            y=iy;
        }
        
    }
    //字母类
  public static class letter
    {
        public point[] pointQue; //坐标序列
        public int Index;//下标
        public char Letter; //字母
        //public point offset; //偏移量
        public  letter() {
        }
        public letter(int Nums,char ltr)
        {
            pointQue = new point[Nums];            //初始化点的数量
            for(int i=0;i<Nums;i++)
            {
                pointQue[i]=new point(0,0);
            }
            Index=0;                //初始化点集下标
            Letter=ltr; //初始化字母
        }
        public int add(int x,int y)
        {
            //每个点都写入点坐标
            pointQue[Index].x=x;
            pointQue[Index].y=y;
            Index++;
            return 0;
        }        
    
        public int offset(int x,int y)
        {
            for(int i=0;i<Index;i++)
            {
                pointQue[i].x+=x;
                pointQue[i].y+=y;
            }
            return 0;
        }
        public int copy(letter src)
        {
            Index=src.Index;
            for(int i=0;i<Index;i++)
            {
                pointQue[i].x=src.pointQue[i].x;
                pointQue[i].y=src.pointQue[i].y;
            }
            
            return 0;
            
        }
    }
   //显示屏类
    public static class screen
     {
        int[][] display;
        int wdt;
        int heg;
        public screen(){}
        public screen(int width,int heigh)
        {            
            display = new int[heigh][width];
            
            //初始化数组是空格
            for(int i=0;i<heigh;i++)
            {
                for(int j=0;j<width;j++)
                {
                    display[i][j]=32;            
                }                
            }
            wdt=width; 
            heg=heigh;
        }
        
        public int addLetter(letter ltr )
        {
            //把字母坐标写到数组里
            for(int i=0;i<ltr.Index;i++)
            {
                display[ltr.pointQue[i].x][ltr.pointQue[i].y]=ltr.Letter;
            }
            return 0;
        }    
        public int displayscreen()
        {
            for(int i=0;i<heg;i++)
            {
                for(int j=0;j<wdt;j++)
                {
                    System.out.print((char)display[i][j]);                    
                }            
                System.out.println();
            }
            return 0;
        }
     }
    
    public static void main(String[] args) {
    
        screen Src=new screen(28,4);
        
      letter J =   new letter(6,'J');
      letter A_1 = new letter(11,'A');
      letter V =   new letter(7,'V');
        letter A_2 = new letter(11,'A');
                
        J.add(0, 3);
        J.add(1, 3);
        J.add(2, 3);
        J.add(3, 2);
        J.add(3, 1);
        J.add(2, 0);
            
        A_1.add(0, 8);
        A_1.add(1, 7);
        A_1.add(1, 9);
        A_1.add(2, 6);
        A_1.add(2, 7);
        A_1.add(2, 8);    
        A_1.add(2, 9);
        A_1.add(2, 10);
        A_1.add(3, 5);
        A_1.add(3, 11);
        
        V.add(0, 13);
        V.add(0, 19);
        V.add(1, 14);
        V.add(1, 18);
        V.add(2, 15);
        V.add(2, 17);
        V.add(3, 16);
        
        A_2.copy(A_1);
        A_2.offset(0, 15);
        
        Src.addLetter(J);
        Src.addLetter(A_1);
        Src.addLetter(V);
        Src.addLetter(A_2);
        Src.displayscreen();
    }

}



  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值