拼出漂亮的表格

來源:互聯網
上載者:User
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 stubfor (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("┴─");} elseSystem.out.print("┘");}}}}private static void add(int j) {// TODO Auto-generated method stubfor (int i = 0; i < j; i++) {System.out.print("│ ");}System.out.println("│");}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.