Description
给你一个矩形的宽度和高度,要求按sample output样例输出此矩形。
Input
输入包含多组数据,每一组包含两个数N和M( 0 < N ,M , < 75 )分别代表矩形的宽和高。输入以EOF结束。
Output
Sample Input
3 2
Sample Output
+—+
| |
| |
+—+
代码块
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner cn = new Scanner(System.in);
while (cn.hasNext()) {
int n = cn.nextInt();
int m = cn.nextInt();
System.out.print('+');
for (int i = 0; i < n; i++) {
System.out.print('-');
}
System.out.println('+');
for (int i = 0; i < m; i++) {
System.out.print('|');
for (int j = 0; j < n; j++) {
System.out.print(' ');
}
System.out.println('|');
}
System.out.print('+');
for (int i = 0; i < n; i++) {
System.out.print('-');
}
System.out.println('+');
}
cn.close();
}
}