VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • 通C#创建一个可以创作朦胧诗的程序

今天我们来讲一下,如果自动写朦胧诗的软件,首先这里创建了一个类"Poem",接下来 创建三个数组

    public static string[] adjective=new string [8]{"美丽的","高兴的","伤心的","失落    的","可爱的","调皮的","活波的","笨拙的"};
    public static string[] subject=new string [8]{"太阳","花朵","星星","月亮","女    孩","小猫","蝴蝶","燕子"};
    public static string[] predicate=new string [7]{"思索着","追赶着","想念着","渴望    着","怒视着","奔跑着","狂喊着"};

接下来,我们来看一下 在主方法用,通过任意组合,就可以创建不同的诗句,如

using System;
class Poem
{
    public static string[] adjective=new string [8]{"美丽的","高兴的","伤心的","失落    的","可爱的","调皮的","活波的","笨拙的"};
    public static string[] subject=new string [8]{"太阳","花朵","星星","月亮","女    孩","小猫","蝴蝶","燕子"};
    public static string[] predicate=new string [7]{"思索着","追赶着","想念着","渴望    着","怒视着","奔跑着","狂喊着"};
    public static void Main()
    {
        string next;
        do
        {
            Random r=new Random ();
            for(int i=1;i<=2;i++)
            {
                Console.WriteLine (adjective[r.Next (adjective.Length )]    +""+subject[r.Next (subject.Length )]+""+predicate[r.Next (predicate.Length )]+""+subject[r.Next (subject.Length )]);
            }
            Console.WriteLine ("你还想看吗?y/n");
            next=Console.ReadLine ();
        }while(next.ToUpper ()!="N");
    } 
}


相关教程