资源限制
时间限制:1.0s 内存限制:512.0MB
问题描述
编写一个程序,输入两个整数,作为栅格的高度和宽度,然后用“+”、“-”和“|”这三个字符来打印一个栅格。
输入格式:输入只有一行,包括两个整数,分别为栅格的高度和宽度。
输出格式:输出相应的栅格。
输入输出样例
样例输入
3 2
————————————————————————————————————————————————
import java.util.Scanner;
public class Main {
static int h;
static int w;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
h = sc.nextInt();
w = sc.nextInt();
sc.close();
if(h <= 0 || w <= 0) return ;
for(int i = 0;i < h;i++) {
for(int j = 0;j < w;j++) {
System.out.print("+-");
}
System.out.printf("+\n");
System.out.println("| | |");
}
for(int j = 0;j < w;j++) {
System.out.print("+-");
}
System.out.printf("+\n");
}
}