zoukankan      html  css  js  c++  java
  • 某公司的一个题面试题(wfcfan)

    是一题笔试题,也没有什么难点,当时写这道题的时候太唐突了,

    今天回来再机子上重新完善完善了
    题面:请打印以下图形

       *
      ***
     *****
    *******
     *****
      ***
       *
    code:
    class Program
        {
            private const string flag = "*";
            private const char snull = ' ';
            private const int length = 7;
    
            static void Main(string[] args)
            {
                for (int i = 0; i <= length; i++)
                {
                    if (i % 2 != 0)
                        PrintFlag(i);
    
                    if (i == length)
                    {
                        for (int j = length - 2; j > 0; j--)
                            if (j % 2 != 0)
                                PrintFlag(j);
                    }
                }
                Console.Read();
            }
    
            static void PrintFlag(int currentIndex)
            {
                string t = string.Empty, s = string.Empty;
                for (int i = 0; i < currentIndex; i++)
                {
                    t += flag;
                }
                s = GetLocation(currentIndex, t);
                Console.WriteLine(s);
            }
    
            static string GetLocation(int currentIndex,string flag)
            {
                int totalcount = length;
                if (currentIndex == totalcount)
                    return flag;
    
                int startlocation = (totalcount - currentIndex) / 2;
                string temp = flag.PadLeft(startlocation + currentIndex, snull);
                temp = temp.PadRight(totalcount, snull);
                return temp;
            }
    }
    
    code2
    class Program{
       static void Main(string[] args)
      {       Console.WriteLine("   *   ");
              Console.WriteLine("  ***  ");
              Console.WriteLine(" ***** ");
          Console.WriteLine("*******");
      Console.WriteLine(" ***** ");
      Console.WriteLine("  ***  ");
       Console.WriteLine("   *   ");
       Console.Read();
     }
    }
    code3
    Console.WriteLine(@"   *
    
      ***
    
     *****
    
    *******
    
     *****
    
      ***
    
       *");
    
    
    code4
    class Program
    {
    static void Main(string[] args)
    {
    PrintStar(9);
    }
    public static void PrintStar(int maxNumber)
    {
    
    //可以在此检验maxNumber是否为奇数
    
    
    ///正打
    for (int i = 1; i <= maxNumber;)
    {
    ShowConsoleStar(i,maxNumber);
    i = i + 2;
    }
    //反打
    for (int i = maxNumber - 2; i >= 1; )
    {
    ShowConsoleStar(i,maxNumber );
    i = i - 2;
    }
    }
    private static void ShowConsoleStar(int starNumber,int maxNumber)
    {
    //补位
    for (int i = 1; i <= (maxNumber - starNumber)/2;i++ )
    {
    Console.Write(" "); 
    }
    //打星
    for (int i = 1; i <=starNumber; i++)
    {
    Console.Write("*"); 
    }
    //换行
    Console.WriteLine(); 
    
    }
    
    }
    
    http://www.cnblogs.com/wfcfan/archive/2009/10/09/1579758.html
  • 相关阅读:
    Oracle导入导出命令
    深入理解JSP/Servlet Session会话管理机制
    Weblogic domain密码的重置方法
    RPC关键要点
    Ubuntu如何配置Telnet服务器
    Win7如何解决telnet不是内部或外部命令!
    Linux系统下的文件权限
    虚拟机系统ubuntu安装VMWare Tools
    SQL模糊查询 LIKE
    Ubuntu下安装SSH
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1741876.html
Copyright © 2011-2022 走看看