zoukankan      html  css  js  c++  java
  • java实现拼出漂亮的表格

    /*
    * 在中文 Windows 环境下,控制台窗口中也可以用特殊符号拼出漂亮的表格来。
    比如:
    ┌─┬─┐
    │ │ │
    ├─┼─┤
    │ │ │
    └─┴─┘
    其实,它是由如下的符号拼接的:
    左上 = ┌
    上 = ┬
    右上 = ┐
    左 = ├
    中心 = ┼
    56
    右 = ┤
    左下= └
    下 = ┴
    右下 = ┘
    垂直 = │
    水平 = ─
    本题目要求编写一个程序,根据用户输入的行、列数画出相应的表格来。
    例如用户输入:
    3 2
    则程序输出:
    ┌─┬─┐
    │ │ │
    ├─┼─┤
    │ │ │
    ├─┼─┤
    │ │ │
    └─┴─┘
    用户输入:
    2 3
    则程序输出:
    ┌─┬─┬─┐
    │ │ │ │
    ├─┼─┼─┤
    │ │ │ │
    └─┴─┴─┘
    要求考生把所有类写在一个文件中。调试好后,存入与考生文件夹下对应题号的“解答.txt”中即可。相关的工程文
    件不要拷入。请不要使用 package 语句。
    另外,源程序中只能出现 JDK1.5 中允许的语法或调用。不能使用 1.6 或更高版本。
    */
    
    
    package Question20_29;
    import java.util.Scanner;
    public class Question28 {
    public static void main(String[] args) {
    Scanner scanner=new Scanner(System.in);
    int hang=scanner.nextInt(),lie=scanner.nextInt();
    for (int i = 0; i < hang; i++) {
    if(i==0){
    System.out.print("┌─");
    for (int j = 0; j < lie-1; j++) {
    System.out.print("┬─");
    }
    System.out.println("┐");
    57
    for (int j = 0; j < lie; j++) {
    System.out.print("│ ");
    }
    System.out.println("│");
    }else {
    System.out.print("├─");
    for (int j = 0; j < lie-1; j++) {
    System.out.print("┼─");
    }
    System.out.println("┤");
    for (int j = 0; j < lie; j++) {
    System.out.print("│ ");
    }
    System.out.println("│");
    }
    }
    System.out.print("└─");
    for (int j = 0; j < lie-1; j++) {
    System.out.print("┴─");
    }
    System.out.println("┘");
    //System.out.print("┌");System.out.print("─");System.out.print("┬");System.out.print("─");System.out.
    print("┐");
    }
    }
    
    
    运行结果:
    请输出两个数,行和列 ,例: 3 4 
    3 4
    ┌─┬─┬─┬─┐
    │ │ │ │ │
    ├─┼─┼─┼─┤
    │ │ │ │ │
    ├─┼─┼─┼─┤
    │ │ │ │ │
    └─┴─┴─┴─┘
    
  • 相关阅读:
    Jstorm执行task报错windows CONFIG SET protected-mode no
    windows搭建redis集群最佳实践
    windows下golang实现Kfaka消息发送及kafka环境搭建
    go报错unimplemented: 64-bit mode not compiled in与mingw 64位安装报错ERROR res已解决
    GoLand配置数据库、远程host以及远程调试
    Go项目中beego的orm使用和gorm的使用
    windows下Go升级及GoLand的安装激活
    记一次解脱
    golang开源项目qor快速搭建网站qor-example运行实践
    使用img2html把图片转为网页
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076876.html
Copyright © 2011-2022 走看看