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

    package cn.dlpu.lby;
    
    import java.util.Scanner;
    
    /*拼出漂亮的表格
     * 在中文Windows环境下,控制台窗口中也可以用特殊符号拼出漂亮的表格来。
     比如:		
     ┌─┬─┐
     │ │ │
     ├─┼─┤
     │ │ │
     └─┴─┘		
     其实,它是由如下的符号拼接的:
     左上 = ┌
     上 =  ┬
     右上 =  ┐
     左 =  ├
     中心 =  ┼
     右 =  ┤
     左下=  └
     下 =  ┴
     右下 =  ┘
     垂直 =  │
     水平 =   ─
     本题目要求编写一个程序,根据用户输入的行、列数画出相应的表格来。
     例如用户输入:
     3 2
     则程序输出:
     ┌─┬─┐
     │ │ │
     ├─┼─┤
     │ │ │
     ├─┼─┤
     │ │ │
     └─┴─┘
     用户输入:
     2 3
     则程序输出:
     ┌─┬─┬─┐
     │ │ │ │
     ├─┼─┼─┤
     │ │ │ │
     └─┴─┴─┘
    
     要求考生把所有类写在一个文件中。调试好后,存入与考生文件夹下对应题号的“解答.txt”中即可。相关的工程文件不要拷入。请不要使用package语句。
     另外,源程序中只能出现JDK1.5中允许的语法或调用。不能使用1.6或更高版本。
     */
    public class Pingezi {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int n = sc.nextInt();
    		int m = sc.nextInt();
    		display(n, m);
    	}
    
    	private static void display(int n, int m) {
    		// TODO Auto-generated method stub
    		for (int i = 0; i <= n; i++) {
    			for (int j = 0; j <= m; j++) {
    				if (i == 0) { // 第一行
    					if (j == 0)
    						System.out.print("┌─");
    					else if (j > 0 && j < m) {
    						System.out.print("┬─");
    					} else {
    						System.out.println("┐");
    						add(j);
    					}
    				}
    
    				// 中间行
    				else if (i > 0 && i < n) {
    					if (j == 0) {
    						System.out.print("├─");
    					} else if (j > 0 && j < m) {
    						System.out.print("┼─");
    					} else{
    						System.out.println("┤");
    						add(j);
    					}
    				}
    
    				// 最后一行
    
    				else{ 
    					if (j == 0) {
    					System.out.print("└─");
    				}
    					else if (j > 0 && j < m){
    					System.out.print("┴─");
    				} else
    					System.out.print("┘");
    				}
    
    			}
    		}
    	}
    
    	private static void add(int j) {
    		// TODO Auto-generated method stub
    		for (int i = 0; i < j; i++) {
    			System.out.print("│ ");
    		}
    		System.out.println("│");
    	}
    }
    


  • 相关阅读:
    JAVA 8的新特性
    JAVA中map的分类和各自的特性
    设计模式之工厂方法模式(附实例代码下载)
    为什么重写equals还要重写hashcode??
    C# static的用法详解
    1-RadioButton控件的用法
    C#三种常用的读取XML文件的方法
    VS2017 中安装SVN
    pip安装selenium时,报错“You are using pip version 10.0.1, however version 18.0 is available.”的问题
    问题:unknown error: call function result missing 'value' 解决方法
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3148245.html
Copyright © 2011-2022 走看看