趣味小程序

来源:http://www.study-code.com/java/j2se/66418.htm

 

/*
*编写一个程序,读入一个正方形的边长,输出一个空心的正方形。
*
*@author 关文柏

*/


import java.io.*;

public class abc
{
 int m;
 //int[][] rect = new int[m][m];
   abc()
 {
   System.out.println("Please input the value:");
   input();
   show();
 }
 void input()
 {
  String s="";
  try
  {
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  s = in.readLine();
  m=Integer.parseInt(s);
 }catch(Exception e){}

 }

 void show()
 {
   int i=0;
  int j=0;
  
  for(i=0;i<m;i++)
  {
   for(j=0;j<m;j++)
   {
    if(i==0)
    {
     System.out.print("*");

    }else

    if(i==(m-1)){
     System.out.print("*");
    }
    else
     if((j==0)&&(i!=0)&&(i!=(m-1))){
     System.out.print("*");
    }else
     if((j==(m-1))&&(i!=0)&&(i!=(m-1))){
    System.out.print("*");
    }else
     if((j!=0)&&(j!=(m-1))&&(i!=0)&&(i!=(m-1))){
    System.out.print("\u0020");
    }
    }
 
   System.out.println("");
  }

 }


 public static void main(String[] args)
 {
  abc a = new abc();


 }
}

posted @ 2008-10-19 17:32  KK in cnblog  阅读(158)  评论(0编辑  收藏  举报