在中文Windows环境下,控制台窗口中也可以用特殊符号拼出漂亮的表格来。
比如:
┌─┬─┐
│ │ │
├─┼─┤
│ │ │
└─┴─┘
其实,它是由如下的符号拼接的:
左上 = ┌
上 = ┬
右上 = ┐
左 = ├
中心 = ┼
右 = ┤
左下= └
下 = ┴
右下 = ┘
垂直 = │
水平 = ─
本题目要求编写一个程序,根据用户输入的行、列数画出相应的表格来。
例如用户输入:
3 2
则程序输出:
┌─┬─┐
│ │ │
├─┼─┤
│ │ │
├─┼─┤
│ │ │
└─┴─┘
用户输入:
2 3
则程序输出:
┌─┬─┬─┐
│ │ │
│
├─┼─┼─┤
│ │ │
│
└─┴─┴─┘
package other;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.TreeSet;
import java.util.Vector;
public class arrays {
public static void main(String[] args) throws IOException
{
int x=6,y=9;
String str1="";
str1=str1+lu;
for (int i = 0; i < y-1; i++) {
str1=str1+le+u;
}
str1=str1+le+ru;
//System.out.println(str1);
String str2="";
str2=str2+v;
for (int i = 0; i < y; i++) {
str2=str2+" "+v;
}
//System.out.println(str2);
String str3="";
str3=str3+l;
for (int i = 0; i < y-1; i++) {
str3=str3+le+m;
}
str3=str3+le+r;
//System.out.println(str3);
String str4="";
str4=str4+ld;
for (int i = 0; i < y-1; i++) {
str4=str4+le+d;
}
str4=str4+le+rd;
//System.out.println(str4);
System.out.println(str1);//第一行出现一次
for (int i = 0; i < x-1; i++)
{//2,3行出现x-1次
System.out.println(str2);
System.out.println(str3);
}
System.out.println(str2);//倒数第二行为str2
System.out.println(str4);//输出最后一行 O(∩_∩)O~ 噢啦
}
}