42:画矩形 /** * 题目名称画矩形 p * 题目来源http://noi.openjudge.cn/ch0105/42/ p * 程序功能根据指定参数输出矩形 * * author 潘磊just_panleijust.edu.cn * version 1.0 */importjava.util.Scanner;publicclassMain{/** * 在指定高度、宽度、符号、空心、实心约束条件下输出相应的矩形。 * * param height 矩形高度。 * param width 矩形宽度。 * param symbol 矩形符号。 * param type 空心实心标记0代表空心1代表实心。 */publicvoidprintRectangle(intheight,intwidth,charsymbol,inttype){/* 依次遍历矩形的每一行 */for(inti1;iheight;i){/* 依次遍历矩形的每一列 */for(intj1;jwidth;j){if(type1){// 如果是实心矩形System.out.print(symbol);// 当前行列位置输出矩形符号}else{// 否则是空心矩形// 如果当前行列是首行或者尾行或者首列或者尾列if(i1||iheight||j1||jwidth){System.out.print(symbol);// 当前行列位置输出矩形符号}else{// 否则当前行列不是首行也不是尾行也不是首列也不是尾列System.out.print( );// 当前行列位置输出空格}}}System.out.println();// 一行输出完毕后输出一个回车}}publicstaticvoidmain(String[]args){MaincallnewMain();ScannerinputnewScanner(System.in);intheightinput.nextInt();intwidthinput.nextInt();charsymbolinput.next().charAt(0);inttypeinput.nextInt();call.printRectangle(height,width,symbol,type);}}