您的位置:首页 > 其它

算法提高 ADV-99 栅格打印问题

2017-08-25 00:22 225 查看
问题描述

  编写一个程序,输入两个整数,作为栅格的高度和宽度,然后用“+”、“-”和“|”这三个字符来打印一个栅格。

  输入格式:输入只有一行,包括两个整数,分别为栅格的高度和宽度。

  输出格式:输出相应的栅格。

  输入输出样例

样例输入

3 2

样例输出

+-+-+
| | |
+-+-+
| | |
+-+-+
| | |
+-+-+

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
if (n==0 || m==0){
return;
}
for (int i=0; i<n*2+1; i++){
for (int j=0; j<m*2+1; j++){
if (i % 2 ==0){
if (j % 2 == 0){
System.out.print("+");
}else{
System.out.print("-");
}
}else{
if (j % 2 == 0){
System.out.print("|");
}else{
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: