初学 用Java画一个空的矩形 谁帮我看看有没有更简便方法
classFunctionTest{publicstaticvoidmain(String[]args){yiHang();zhongJian();yiHang();}p...
class FunctionTest
{
public static void main(String[] args)
{
yiHang();
zhongJian();
yiHang();
}
public static void yiHang()
{
for (int x=1;x<=9;x++)
{
System.out.print("*");
}
System.out.println("*");
return ;
}
public static void zhongJian()
{
for (int x =1;x<=5;x++ )
{
System.out.print("*");
for (int y =1;y<9 ;y++ )
{
System.out.print(" ");
}
System.out.println("*");
}
return ;
}
} 展开
{
public static void main(String[] args)
{
yiHang();
zhongJian();
yiHang();
}
public static void yiHang()
{
for (int x=1;x<=9;x++)
{
System.out.print("*");
}
System.out.println("*");
return ;
}
public static void zhongJian()
{
for (int x =1;x<=5;x++ )
{
System.out.print("*");
for (int y =1;y<9 ;y++ )
{
System.out.print(" ");
}
System.out.println("*");
}
return ;
}
} 展开
展开全部
代码如下:
public class FunctionTest {
public static void main(String[] 搭则args) {
int m = 7, n = 10;
for (int i 悄乱= 0; i < m; i++) 知运棚{
for (int j = 0; j < n; j++) {
if (i == 0 || i == (m - 1)) {
System.out.print("*");
} else if (j == 0 || j == (n - 1)) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
运行结果:
展开全部
import java.util.Scanner; public class TestArea { public static void main(String[] args) { Scanner s = new Scanner(System.in); int [] in=new int[2]; System.out.println("请输入矩形的伏庆则长和宽:"); for(int i=0;i<2;i++) { in[i]=s.nextInt(); } System.out.println("缺棚矩形的周长为:"+2*(in[0]+in[1])+";\n面积为:"差搭+in[0]*in[1]); } }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询