package com.bird.software; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Test9 { private static List<String> list; private static void init(){ list = new ArrayList<String>(); list.add("┌");//左上 = ┌ 0 list.add("┬");//上 = ┬ 1 list.add("┐");//右上 = ┐ 2 list.add("├");//左 = ├ 3 list.add("┼");//中心 = ┼ 4 list.add("┤");//右 = ┤ 5 list.add("└");//左下= └ 6 list.add("┴");//下 = ┴ 7 list.add("┘");//右下 = ┘ 8 list.add("│");//垂直 = │ 9 list.add("─");//水平 = ─ 10 } /** * 输出左上 */ private static void top(){ System.out.print(list.get(0)); } /** * 输出- + */ private static void top2(){ System.out.print(list.get(10)+list.get(1)); } /** * 输出右上 */ private static void top3(){ System.out.print(list.get(2)); } /** * 输出垂直 */ private static void vertix(){ System.out.print(list.get(9)+" "); } /** * 输出左 */ private static void medium(){ System.out.print(list.get(3)); } /** * 输出中心 */ private static void medium1(){ System.out.print(list.get(10)+list.get(4)); } /** * 输出右 */ private static void medium2(){ System.out.println(list.get(5)); } /** * 输出左下 */ private static void buttom(){ System.out.print(list.get(6)); } /** * 输出下- */ private static void buttom2(){ System.out.print(list.get(10)+list.get(7)); } /** * 输出右下 */ private static void buttom3(){ System.out.print(list.get(8)); } private static void service(int row, int col){ init(); //第一层 top(); for(int i = 0; i < col-1; i++) top2(); System.out.print(list.get(10)); top3(); System.out.println(); //第二层 for(int t = 0; t < row-1; t++){ for(int i = 0; i <= col; i++) vertix(); //第三层 System.out.println(); medium(); for(int i = 0; i < col-1; i++) medium1(); System.out.print(list.get(10)); medium2(); } //第四层 for(int i = 0; i <= col; i++) vertix(); //第五层 System.out.println(); buttom(); for(int i = 0; i < col-1; i++) buttom2(); System.out.print(list.get(10)); buttom3(); } public static void main(String[] args) { System.out.println("请输入需要创建的行和列"); Scanner sc = new Scanner(System.in); System.out.println("行等于"); int row = sc.nextInt(); System.out.println("列数等于"); int col = sc.nextInt(); service(row,col); } }
运行结果如下