42:画矩形
/** * 题目名称:画矩形 <p> * 题目来源:http://noi.openjudge.cn/ch0105/42/ <p> * 程序功能:根据指定参数输出矩形 * * @author 潘磊,just_panlei@just.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(inti=1;i<=height;i++){/* 依次遍历矩形的每一列 */for(intj=1;j<=width;j++){if(type==1){// 如果是实心矩形System.out.print(symbol);// 当前行列位置输出矩形符号}else{// 否则,是空心矩形// 如果当前行列是首行或者尾行或者首列或者尾列if(i==1||i==height||j==1||j==width){System.out.print(symbol);// 当前行列位置输出矩形符号}else{// 否则,当前行列不是首行也不是尾行也不是首列也不是尾列System.out.print(' ');// 当前行列位置输出空格}}}System.out.println();// 一行输出完毕后,输出一个回车}}publicstaticvoidmain(String[]args){Maincall=newMain();Scannerinput=newScanner(System.in);intheight=input.nextInt();intwidth=input.nextInt();charsymbol=input.next().charAt(0);inttype=input.nextInt();call.printRectangle(height,width,symbol,type);}}