打印明星比形状更好 [英] Print Stars in Greather than shape
问题描述
我希望这种形状的星星打印
*
*
*
*
*
*
*
*
*
我认为这是你的面试问题,我遇到了我在采访中的同样问题,当我更新鲜时。
使用系统;
class 计划
{
静态 void Main()
{
for ( int i = 5 ; i > = 0 ; i--)
{
// function();
Console.WriteLine(缩进(i)+ *);
}
for ( int i = 1 ; i< = 5 ; i ++)
{
// function();
Console.WriteLine(缩进(i)+ ) *);
}
Console.ReadKey();
}
public static string 缩进( int count)
{
return .PadLeft(count);
}
}
在您发布问题之前,请尝试使用您所知道的内容。
解决方案1:
protected void PrintGreater()
{
for(int i = 5; i> = 1; i--)
{
for(int j = 1; j< ; i; j ++)
{
Response.Write(& nbsp;& nbsp;& nbsp;);
}
Response.Write(*+< br />);
}
for(int j = 1; j< = 5; j ++)
{< br />
for(int i = 1; i< j; i ++)
{
Response.Write(& nbsp;& nbsp;& nbsp;);
}
Response.Write(*+< br />);
}
}
解决方案2:
protected void PrintGreater()
{
for(int i = 5; i> = 1; i--)
{
for(int j = 1; j< i; j ++)
{
Response.Write( );
}
Response.Write(* +
);
}
for (int j = 2; j< = 5; j ++)
{
for(int i = 1; i< j; i ++)
{
=
=response.write(& nbsp;& & nbsp;);
=}
=response.write(*=+ =< br =>);
}
}
希望这对你有用。
快乐编码:)
i want star print in this shape
* * * * * * * * *解决方案I think its your Interview question ,I faced the same question in my interview when I'm a fresher.
using System; class Program { static void Main() { for (int i = 5; i >=0; i--) { //function(); Console.WriteLine(Indent(i) + "*"); } for (int i = 1; i<= 5; i++) { //function(); Console.WriteLine(Indent(i) + "*"); } Console.ReadKey(); } public static string Indent(int count) { return "".PadLeft(count); } }
And before you post your question try something with what you know.
Solution 1:
protected void PrintGreater()
{
for (int i = 5; i >=1; i--) { for (int j = 1; j < i; j++) { Response.Write(" "); } Response.Write("*"+ "<br/>"); } for(int j=1;j<=5;j++) {<br /> for(int i=1;i<j;i++) { Response.Write(" "); } Response.Write("*" + "<br/>"); } }
Solution 2:
protected void PrintGreater()
{
for (int i = 5; i >=1; i--)
{
for (int j = 1; j < i; j++)
{
Response.Write(" ");
}
Response.Write("*"+ "
");
}
for(int j=2;j<=5;j++)
{
for(int i=1;i<j;i++)
{
=""
="" response.write(" ");
="" }
="" response.write("*"="" +="" "<br="">");
}
}
hope this will work for you.
Happy coding :)
这篇关于打印明星比形状更好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!