c#编写一个程序,打印用星号(*)绘制的方框(正方形),每条边5个*
6个回答
展开全部
using System;
using System.Collections.Generic;
using System.Text;
namespace c
{
class Point
{
public int x;
public int y;
public Point(int nx, int ny)
{
Set(nx, ny);
}
public Point(Point n)
{
Set(n);
}
public void Set(int nx, int ny)
{
x = nx;y = ny;
}
public void Set(Point n)
{
x = n.x;
y = n.y;
}
public int getx()
{
return x;
}
public int gety()
{
return y;
}
}
class Class1
{
private int side;
private Point location;
public Class1(Point location,int length)
{
this.side = length;
this.location = location;
graph(location, length);
}
public void Class(Point center,int length)
{ }
public void graph(Point center,int length)
{
for(int i = 0; i < center.y; i++) Console.WriteLine("");
for(int i = 0; i < length; i++)
{
string line = "";
for(int j = 0; j < center.x * 2 + length * 2 - 1; j++)
{
if(i == 0 || i == length - 1)
{
if(j >= center.x * 2 && (j - center.x * 2) % 2 == 0) line+="*";
else line+=" ";
}
else
{
if(j == center.x * 2 || j == center.x * 2 + length * 2 - 2) line+="*";
else line+=" ";
}
}
Console.WriteLine(line);
}
}
public int getarea()
{
return side*side;
}
public int getperimeter()
{
return side*4;
}
public int getlength()
{
return side;
}
public Point getlocation()
{
return location;
}
}
class program
{
static void Main(string[] args)
{
int x, y, a;
Console.WriteLine("请输入正方形的边长及位置:");
Console.WriteLine("边长:");
a = int.Parse(Console.ReadLine());
Console.WriteLine("位置:");
x = int.Parse(Console.ReadLine());
y = int.Parse(Console.ReadLine());
Class1 sd = new Class1(new Point(x, y), a);
Console.WriteLine("Square:");
Console.WriteLine("Length=" + sd.getlength());
Console.WriteLine("Location=" + sd.getlocation().getx() + "," + sd.getlocation().gety());
Console.WriteLine("Perimeter=" + sd.getperimeter());
Console.WriteLine("Area=" + sd.getarea());
}
}
}
运行时输入边长:5 位置:5
using System.Collections.Generic;
using System.Text;
namespace c
{
class Point
{
public int x;
public int y;
public Point(int nx, int ny)
{
Set(nx, ny);
}
public Point(Point n)
{
Set(n);
}
public void Set(int nx, int ny)
{
x = nx;y = ny;
}
public void Set(Point n)
{
x = n.x;
y = n.y;
}
public int getx()
{
return x;
}
public int gety()
{
return y;
}
}
class Class1
{
private int side;
private Point location;
public Class1(Point location,int length)
{
this.side = length;
this.location = location;
graph(location, length);
}
public void Class(Point center,int length)
{ }
public void graph(Point center,int length)
{
for(int i = 0; i < center.y; i++) Console.WriteLine("");
for(int i = 0; i < length; i++)
{
string line = "";
for(int j = 0; j < center.x * 2 + length * 2 - 1; j++)
{
if(i == 0 || i == length - 1)
{
if(j >= center.x * 2 && (j - center.x * 2) % 2 == 0) line+="*";
else line+=" ";
}
else
{
if(j == center.x * 2 || j == center.x * 2 + length * 2 - 2) line+="*";
else line+=" ";
}
}
Console.WriteLine(line);
}
}
public int getarea()
{
return side*side;
}
public int getperimeter()
{
return side*4;
}
public int getlength()
{
return side;
}
public Point getlocation()
{
return location;
}
}
class program
{
static void Main(string[] args)
{
int x, y, a;
Console.WriteLine("请输入正方形的边长及位置:");
Console.WriteLine("边长:");
a = int.Parse(Console.ReadLine());
Console.WriteLine("位置:");
x = int.Parse(Console.ReadLine());
y = int.Parse(Console.ReadLine());
Class1 sd = new Class1(new Point(x, y), a);
Console.WriteLine("Square:");
Console.WriteLine("Length=" + sd.getlength());
Console.WriteLine("Location=" + sd.getlocation().getx() + "," + sd.getlocation().gety());
Console.WriteLine("Perimeter=" + sd.getperimeter());
Console.WriteLine("Area=" + sd.getarea());
}
}
}
运行时输入边长:5 位置:5
展开全部
using System;
using System.Collections.Generic;
using System.Text;
namespace reviewBase
{
class Program
{
static void Main()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (i == 0 || i == 4 || j == 0 || j == 4)
Console.Write("*\0");//一个星一个空格
else
Console.Write("\0\0");//两个空格
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Text;
namespace reviewBase
{
class Program
{
static void Main()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (i == 0 || i == 4 || j == 0 || j == 4)
Console.Write("*\0");//一个星一个空格
else
Console.Write("\0\0");//两个空格
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
Console.Write("* ");
Console.WriteLine();
}
Console.ReadLine();
}
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
Console.Write("* ");
Console.WriteLine();
}
Console.ReadLine();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2008-11-26
展开全部
for(int i=0;i<5;i++){
if(i==0 || i==4){
for(int j=0;j<5;j++)
Console.Write("*");
}else{
Console.Write("*");
for(int j=0;j<4;j++)
Console.Write(" ");
Console.Write("*");
}
Console.WriteLine();
}
if(i==0 || i==4){
for(int j=0;j<5;j++)
Console.Write("*");
}else{
Console.Write("*");
for(int j=0;j<4;j++)
Console.Write(" ");
Console.Write("*");
}
Console.WriteLine();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadLing();
{
for(int j=1;j<=i;j++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadLing();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询