【练习】15年9月实现的一个打印空心矩形

来源:互联网 发布:大数据时代 bbc 下载 编辑:程序博客网 时间:2024/05/30 04:12
/*
打印一个空心矩形……
*/
import java.util.Scanner;
class Demo8 
{
public static void main(String[] args) 
{
System.out.print("请分别输入您要打印的矩形的长和宽:");
Scanner sc=new Scanner(System.in);
int weight=sc.nextInt();
int height=sc.nextInt();
very(height,weight);
}
public static void very(int a,int b)
{
outer:for (int i=1;i<=a; i++)
{
inner:for (int j=1;j<=b ;j++ )
{
if (i==1||i==a)
{
System.out.print("*");
}else if (j!=1&&j!=b)
{
System.out.print(" ");
}
else if (j==1||j==b)
{
System.out.print("*");
}
else
{
continue;
   }
    }System.out.println();
}
}
}

0 0
原创粉丝点击