package com.demo2;
import java.util.Scanner;
/*
* Give you the width and height of the rectangle(矩形),darw it.
*
* 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.
*
* 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.
*
*/
public class HDU_oj2052 {
public static void main(String[] args) {
Scanner sn = new Scanner(System.in);
while (sn.hasNext()) {
int width = sn.nextInt();
int height = sn.nextInt();
width = width + 2;
height = height + 2;
/*
* width: 3 height:2
* +---+
* | |
* | |
* +---+
*/
char[][] arr = new char[height][width];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (i == 0 || i == height - 1) {
if (j == 0 || j == width - 1)
arr[i][j] = '+';
else
arr[i][j] = '-';
} else if ((i > 0 && i < height - 1) && (j == 0 || j == width - 1)) {
arr[i][j] = '|';
} else {
arr[i][j] = ' ';
}
}
}
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
System.out.print(arr[i][j]);
}
System.out.println();
}
System.out.println();
}
sn.close();
}
}
杭电oj —— 2052
猜你喜欢
转载自blog.csdn.net/LiLi_code/article/details/88551328
今日推荐
周排行