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
    ┌─┬─┬─┬─┐
    │ │ │ │ │
    ├─┼─┼─┼─┤
    │ │ │ │ │
    ├─┼─┼─┼─┤
    │ │ │ │ │
    └─┴─┴─┴─┘
    
  • 相关阅读:
    antd按需加载
    解决vscode开发react项目没有代码提示问题
    在react中配置less
    flutter之fluro导航传参数
    Flutter游戏:简单规则与结束页
    zsh: command not found:XXX
    React的安装与使用
    git stash 用法总结和注意点
    【OSS】工具类
    ajax将数组或list集合传到后台 的 【坑】
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076876.html
Copyright © 2011-2022 走看看