HDOJ2052_Picture

来源:互联网 发布:oracle数据库密码策略 编辑:程序博客网 时间:2024/05/21 22:28
Problem Description
Give you the width and height of the rectangle,darw it.
 
Input
Input contains a number of test cases.For each case ,there are two numbers n and m (0 < n,m < 75)indicate the width and height of the rectangle.Iuput ends of EOF.
 
Output
For each case,you should draw a rectangle with the width and height giving in the input.
after each case, you should a blank line.
 
Sample Input
3 2
 
Sample Output
+---+| || |+---+
@@题目要求输入宽高,然后输出一个类似上图的图形
import java.util.Scanner;public class P2052 {private static Scanner scanner;public static void main(String[] args) {scanner = new Scanner(System.in);while (scanner.hasNext()) {int n = scanner.nextInt();// 宽int m = scanner.nextInt();// 高for (int i = 1; i <= m + 2; i++) {if (i == 1 || i == m + 2) {// 第一个行System.out.print("+");} else {System.out.print("|");}for (int j = 1; j <= n; j++) {if (i == 1 || i == m + 2) {// 第一个行或者最后一行System.out.print("-");} else {System.out.print(" ");}}if (i == m + 2 || i == 1) {// 最后一行System.out.print("+");} else {System.out.print("|");}System.out.println();}System.out.println();}}}


原创粉丝点击