C#打印星号问题
usingSystem;classPrint{publicPrint(){}publicVoidgo(intn){intm;inta;intb;intc;intd;int...
using System; class Print { public Print() {} public Void go(int n) { int m; int a; int b; int c; int d; int e; int f; int x; int y; int s; s = 2 * n - 1; for (i = 1; i <= n; i++) { m = 2 * i - 1; for (a = 1; a <= (s - m) / 2; a++) { Console.Write(" "); } for (b = 1; b <= m; b++) { Console.Write("*"); } for (c = 1; c <= (s - m) / 2; c++) { Console.WriteLine(" "); } } for (x = n - 1; x >= 1; x--) { y = 2 * x - 1; for (d = 1; d <= (s - m) / 2; d++) { Console.Write(" "); } for (e = 1; e <= m; e++) { Console.Write("*"); } for (f = 1; f <= (s - m) / 2; f++) { Console.WriteLine(" "); } } } } class MainClass { public Void Main(string[] args) { int line = Console.ReadLine(); Print me = new Print(); me.print(line); } } 用SDK编译后发生错误 C#无法使用 system.void 求救啊
展开
3个回答
展开全部
class Print { public Print() { } public void go(int n)// void关键字错写成Void { int m=0;// m需要初始化 int a; int b; int c; int d; int e; int f; int x; int y; int s; s = 2 * n - 1; for (int i = 1; i <= n; i++)// i未声明 { m = 2 * i - 1; for (a = 1; a <= (s - m) / 2; a++) { Console.Write(" "); } for (b = 1; b <= m; b++) { Console.Write("*"); } for (c = 1; c <= (s - m) / 2; c++) { Console.WriteLine(" "); } } for (x = n - 1; x >= 1; x--) { y = 2 * x - 1; for (d = 1; d <= (s - m) / 2; d++) { Console.Write(" "); } for (e = 1; e <= m; e++) { Console.Write("*"); } for (f = 1; f <= (s - m) / 2; f++) { Console.WriteLine(" "); } } } } class MainClass { static void Main(string[] args)// void关键字错写成Void,入口点的“Main”方法应该为静态 { int line = int.Parse(Console.ReadLine());// 需要显示将类型“string”隐式转换为“int” Print me = new Print(); me.go(line);// 应该调用成员函数go } }
展开全部
老大, 这是c# , 不是c++ 这两种语言的区别还蛮大的 就拿显示来说 就不是这样的 加我,我给你说说把
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建议类成员函数的实现放在类的外部。class的定义后应该是有分号的吧,c++是的,这个不清楚。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询