diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/Guess.json" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/Guess.json" new file mode 100644 index 0000000000000000000000000000000000000000..8a644fd01afa42a12dea6950d00a3e7ef8386d41 --- /dev/null +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/Guess.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "huanhuilong", + "source": "Guess.md" +} \ No newline at end of file diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/Guess.md" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/Guess.md" new file mode 100644 index 0000000000000000000000000000000000000000..89aedc5f8afc914b14f244d4400f3ebd3aa2b3b7 --- /dev/null +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/Guess.md" @@ -0,0 +1,148 @@ +# 猜数字 + +使用C#编写一个猜数字游戏,以下实现没有错误的代码是? + +## 答案 + +```csharp +public class Program{ + public static void Main(string[] args){ + Random rand = new Random(); + int success = 0; + while(true){ + int number = rand.Next(0,5); + bool replay = false; + Console.Write("我想好了一个0-5内的数字,你猜是多少?输入你的猜测或输入q退出: "); + while(true){ + string val = Console.ReadLine(); + if(val=="q"){ + break; + } + int a = Convert.ToInt32(val); + if(a==number){ + success +=1; + Console.WriteLine("恭喜你才对了,是否再来一个?[y/n]:"); + string ret = Console.ReadLine(); + replay = ret=="y"; + break; + }else{ + Console.WriteLine("猜错了,再来一次或输入q退出:"); + } + } + if(!replay){ + break; + } + } + Console.WriteLine("太棒了,你一共猜对了{0}次!", success); + } +} +``` + +## 选项 + +### A + +```csharp +public class Program{ + public static void Main(string[] args){ + Random rand = new Random(0,5); + int success = 0; + while(true){ + int number = rand.Next(); + bool replay = false; + Console.Write("我想好了一个0-5内的数字,你猜是多少?输入你的猜测或输入q退出: "); + while(true){ + string val = Console.ReadLine(); + if(val=="q"){ + break; + } + int a = Convert.ToInt32(val); + if(a==number){ + success +=1; + Console.WriteLine("恭喜你才对了,是否再来一个?[y/n]:"); + string ret = Console.ReadLine(); + replay = ret=="y"; + break; + }else{ + Console.WriteLine("猜错了,再来一次或输入q退出:"); + } + } + if(!replay){ + break; + } + } + Console.WriteLine("太棒了,你一共猜对了{0}次!", success); + } +} +``` + +### B + +```csharp +public class Program{ + public static void Main(string[] args){ + Random rand = new Random(); + int success = 0; + while(true){ + int number = rand.Next(0,5); + bool replay = false; + Console.Write("我想好了一个0-5内的数字,你猜是多少?输入你的猜测或输入q退出: "); + while(true){ + string val = Console.Read(); + if(val=="q"){ + break; + } + int a = Convert.ToInt32(val); + if(a==number){ + success +=1; + Console.WriteLine("恭喜你才对了,是否再来一个?[y/n]:"); + string ret = Console.Read(); + replay = ret=="y"; + break; + }else{ + Console.WriteLine("猜错了,再来一次或输入q退出:"); + } + } + if(!replay){ + break; + } + } + Console.WriteLine("太棒了,你一共猜对了{0}次!", success); + } +} +``` + +### C + +```csharp +public class Program{ + public static void Main(string[] args){ + Random rand = new Random(); + int success = 0; + while(true){ + int number = rand.Next(0,5); + bool replay = false; + Console.Write("我想好了一个0-5内的数字,你猜是多少?输入你的猜测或输入q退出: "); + while(true){ + var val = Console.ReadLine(); + if(val=="q"){ + break; + } + if(val==number){ + success +=1; + Console.WriteLine("恭喜你才对了,是否再来一个?[y/n]:"); + string ret = Console.ReadLine(); + replay = ret=="y"; + break; + }else{ + Console.WriteLine("猜错了,再来一次或输入q退出:"); + } + } + if(!replay){ + break; + } + } + Console.WriteLine("太棒了,你一共猜对了{0}次!", success); + } +} +``` diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/config.json" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/config.json" index 88f332cb758026a4ae0105e82633cd81e784e57f..11d9620153172f942f71db59143d477ee11e6fa4 100644 --- "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/config.json" +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/config.json" @@ -2,5 +2,7 @@ "node_id": "csharp-ecdbead6dc0f4676b048a3d3d6a31741", "keywords": [], "children": [], - "export": [] + "export": [ + "Guess.json" + ] } \ No newline at end of file diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/sample/Program.cs" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/sample/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..53d409bcd312ddf706f5dfa40b764759ee817880 --- /dev/null +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/sample/Program.cs" @@ -0,0 +1,32 @@ + +public class Program{ + public static void Main(string[] args){ + Random rand = new Random(); + int success = 0; + while(true){ + int number = rand.Next(0,5); + bool replay = false; + Console.Write("我想好了一个0-5内的数字,你猜是多少?输入你的猜测或输入q退出: "); + while(true){ + string val = Console.Read(); + if(val=="q"){ + break; + } + int a = Convert.ToInt32(val); + if(a==number){ + success +=1; + Console.WriteLine("恭喜你才对了,是否再来一个?[y/n]:"); + string ret = Console.Read(); + replay = ret=="y"; + break; + }else{ + Console.WriteLine("猜错了,再来一次或输入q退出:"); + } + } + if(!replay){ + break; + } + } + Console.WriteLine("太棒了,你一共猜对了{0}次!", success); + } +} \ No newline at end of file diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/sample/sample.csproj" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/sample/sample.csproj" new file mode 100644 index 0000000000000000000000000000000000000000..40c60dd4c884340c455eab8a0020f7c681a4e76c --- /dev/null +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/5.\344\275\277\347\224\250C#\344\273\216.NET\347\261\273\345\272\223\350\260\203\347\224\250\346\226\271\346\263\225/sample/sample.csproj" @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + +