文章标题

for循环的控制;和main方法的执行;

package cn.com.dasnelin.test;

public class DrawFigure {
    public static void main (String[]args){
        drawLine();
        drawTop();
        drawBottom();
        drawLine();
    }
    public static void drawLine(){
        System.out.print("+");
        for(int i=1;i<=6;i++){
            System.out.print("-");
        };
        System.out.println("+");//输出后再换行。
    }
    public static void drawTop(){
        for(int line=1;line<=3;line++){
            System.out.print("|");
            for(int i=1;i<=(line-1);i++){
                System.out.print(" ");
            }
            System.out.print("\\");
            for(int i=1;i<=(6-2*line);i++){
                System.out.print(".");
            }
            System.out.print("/");
            for(int i=1;i<=(line-1);i++){
                System.out.print(" ");//注意空格;
            }
            System.out.println("|");
        }
    }
    public static void drawBottom(){
        for(int line=1;line<=3;line++){
            System.out.print("|");
            for(int i=1;i<=(3-line);i++){
                System.out.print(" ");
            }
            System.out.print("/");
            for(int i=1;i<=2*(line-1);i++){
                System.out.print(".");
            }
            System.out.print("\\");
            for(int i=1;i<=(3-line);i++){
                System.out.print(" ");
            }
            System.out.println("|");
        }
    }
}

你可能感兴趣的:(for循环)