HDOJ2052_Picture
原创
©著作权归作者所有:来自51CTO博客作者wx62eb7326068f3的原创作品,请联系作者获取转载授权,否则将追究法律责任
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();
}
}
}