填空题,简单的求长度,你可以直接数,也可也将图形导入成为一个字符串,然后切割成数组,遍历数组,如果数组的元素等于# or @ 那么就+1 or +2即可;
记得算上头尾,一共+2;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
//先得到图形
String str = "+-------------------------------------------------+"+
"| |"+
"| H###### #### |"+
"| # # # |"+
"| # # # |"+
"| # #### # # |"+
"| # # # # # |"+
"| ######@### # # |"+
"| # #### # # |"+
"| # # # # # |"+
"| ####@#######@### # # |"+
"| # # # # # |"+
"| T ##### # # # ## |"+
"| # # ### ### ## |"+
"| ################ # # #### |"+
"| # # # # |"+
"| ############## #######@########## |"+
"| # ### |"+
"| ########################### |"+
"+-------------------------------------------------+";
//转换成数组,对每一个元素进行判断
String s[] = str.split("");
int number = 0;
for(String str1 : s){
if(str1.equals("#")){
number++;
}else if(str1.equals("@")){
number += 2;
}
}
//加上头尾
number +=2;
System.out.println(number);
}
}