博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
拼出漂亮的表格
阅读量:4625 次
发布时间:2019-06-09

本文共 1614 字,大约阅读时间需要 5 分钟。

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("│");	}}

转载于:https://www.cnblogs.com/dyllove98/p/3148245.html

你可能感兴趣的文章
也谈智能手机游戏开发中的分辨率自适应问题
查看>>
关于 IOS 发布的点点滴滴记录(一)
查看>>
《EMCAScript6入门》读书笔记——14.Promise对象
查看>>
CSS——水平/垂直居中
查看>>
Eclipse连接mysql数据库jdbc下载(图文)
查看>>
Python中Selenium的使用方法
查看>>
三月23日测试Fiddler
查看>>
20171013_数据库新环境后期操作
查看>>
SpringMVC中文件的上传(上传到服务器)和下载问题(二)--------下载
查看>>
Socket & TCP &HTTP
查看>>
osip及eXosip的编译方法
查看>>
Hibernate composite key
查看>>
[CF Round #294 div2] D. A and B and Interesting Substrings 【Map】
查看>>
keepalived+nginx安装配置
查看>>
vue+element-ui实现表格checkbox单选
查看>>
autofac
查看>>
MacOS 系统终端上传文件到 linux 服务器
查看>>
Excel导出POI
查看>>
兼容性
查看>>
自动执行sftp命令的脚本
查看>>