输入#的个数:

来源:互联网 发布:数据帧格式设计 编辑:程序博客网 时间:2024/05/29 16:59

 /*输出:
#  #  #  #
#           #
#           #
#  #  #  #
*/

import java.util.Scanner;public class Rectangle1 {public void DoDraw(int n){//String str ="";for(int i = 0;i < n;i++){for(int j = 0;j < n;j++){if(j == 0 || j == n - 1 || i == 0 || i == n - 1){System.out.print("# ");}else{System.out.print("  ");}}System.out.println();}//return str;}public static void main(String[]args){Scanner in = new Scanner(System.in);System.out.println("请输入正方形的边长:");int n =in.nextInt();Rectangle1 r = new Rectangle1();//System.out.print(r.DoDraw(n));r.DoDraw(n);}}

原创粉丝点击