C#练习——统计整型数组中不重复数字的个数、将普通日期格式转换成汉字日期格式、在控制台录入每个学生的姓名,当用户输入quit(不区分大小写)时,程序停止接受用户的输入,并且显示出用户输入的学生的个数
来源:互联网 发布:淘宝直播开通后怎么办 编辑:程序博客网 时间:2024/05/16 17:54
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReviewPractice
{
class Program
{
static void Main(string[] args)
{
#region 1、请统计出数组:{1,2,3,4,5,6,7,8,9,1,2,3,79,23,45,64,9,3,2,4}中的不重复的数字的个数。2、将数组中重复数字去掉后放入一个新的数组中
#region 1、统计数组中不重复数字的个数
//int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 79, 23, 45, 64, 9, 3, 2, 4 };
////统计数组中不重复数字的个数
//int count = 0;
//for (int i = 0; i < array.Length; i++)
//{
// //判断是否重复
// bool b = true;
// for (int j = 0; j < array.Length; j++)
// {
// //假如在不同的索引位置两个数相等
// if (array[i] == array[j] && i != j)
// {
// b = false;
// break;
// }
// }
// //假如不重复
// if(b)
// {
// count++;
// }
//}
//Console.WriteLine("不重复数字的个数为:{0}",count);
//Console.ReadKey();
#endregion
#region 2、将重复数字去掉并放入一个新的数组中
//int[] arrayInt = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 79, 23, 45, 64, 9, 3, 2, 4 };
////对数组进行排序
//Array.Sort(arrayInt);
//List<int> list = new List<int>();
//for (int i = 0; i < arrayInt.Length - 1; i++)
//{
// if (arrayInt[i] != arrayInt[i + 1])
// {
// list.Add(arrayInt[i]);
// }
//}
//list.Add(arrayInt[arrayInt.Length - 1]);
//for (int i = 0; i < list.Count; i++)
//{
// Console.WriteLine(list[i]);
//}
//Console.ReadKey();
#endregion
#endregion
#region 制作一个控制台小程序。要求:用户可以在控制台录入每个学生的姓名,当用户输入quit(不区分大小写)时,程序停止接受用户的输入,并且显示出用户输入的学生的个数,以及每个学生的姓名。再增加一个显示姓“王”的同学的个数,此处不考虑复姓问题。
//List<string> strList = new List<string>();
////统计姓王的同学的个数
//int count = 0;
//string name;
//do
//{
// Console.WriteLine("请输入学生姓名:");
// name = Console.ReadLine();
// strList.Add(name);
// //如果名字中第一个字符是王
// if (name.IndexOf('王') == 0)
// {
// count++;
// }
//}
//while (name.ToLower() != "quit");
////去掉quit
//strList.RemoveAt(strList.Count - 1);
//Console.WriteLine("您一共录入{0}个学生,姓王同学的个数为:{1},名字分别为:", strList.Count,count);
//foreach (string strName in strList)
//{
// Console.WriteLine(strName);
//}
//Console.ReadKey();
#endregion
#region 将普通日期格式:“2011年6月4日” 转换成汉字日期格式:“二零一一年六月四日”。暂时不考虑10日、13日、23日等“带十”的问题。
//while(true)
//{
// Console.WriteLine("请输入一个日期:");
// string date = Console.ReadLine();
// date = ConvertData(date);
// Console.WriteLine(date);
// Console.ReadKey();
//}
#endregion
}
/// <summary>
/// 将普通日期格式转换成汉字日期格式
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
private static string ConvertData(string date)
{
//不能直接修改字符串,比如data[0]='零',字符串具有不可变性
//先根据字符串data生成一个char数组(字符数组)
char[] chs = date.ToCharArray();
for (int i = 0; i < chs.Length; i++)
{
switch(chs[i])
{
case '0':chs[i] = '零';
break;
case '1':
chs[i] = '一';
break;
case '2':
chs[i] = '二';
break;
case '3':
chs[i] = '三';
break;
case '4':
chs[i] = '四';
break;
case '5':
chs[i] = '五';
break;
case '6':
chs[i] = '六';
break;
case '7':
chs[i] = '七';
break;
case '8':
chs[i] = '八';
break;
case '9':
chs[i] = '九';
break;
}
}
//return date;
//将char数组转化为字符串string
return new string(chs);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReviewPractice
{
class Program
{
static void Main(string[] args)
{
#region 1、请统计出数组:{1,2,3,4,5,6,7,8,9,1,2,3,79,23,45,64,9,3,2,4}中的不重复的数字的个数。2、将数组中重复数字去掉后放入一个新的数组中
#region 1、统计数组中不重复数字的个数
//int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 79, 23, 45, 64, 9, 3, 2, 4 };
////统计数组中不重复数字的个数
//int count = 0;
//for (int i = 0; i < array.Length; i++)
//{
// //判断是否重复
// bool b = true;
// for (int j = 0; j < array.Length; j++)
// {
// //假如在不同的索引位置两个数相等
// if (array[i] == array[j] && i != j)
// {
// b = false;
// break;
// }
// }
// //假如不重复
// if(b)
// {
// count++;
// }
//}
//Console.WriteLine("不重复数字的个数为:{0}",count);
//Console.ReadKey();
#endregion
#region 2、将重复数字去掉并放入一个新的数组中
//int[] arrayInt = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 79, 23, 45, 64, 9, 3, 2, 4 };
////对数组进行排序
//Array.Sort(arrayInt);
//List<int> list = new List<int>();
//for (int i = 0; i < arrayInt.Length - 1; i++)
//{
// if (arrayInt[i] != arrayInt[i + 1])
// {
// list.Add(arrayInt[i]);
// }
//}
//list.Add(arrayInt[arrayInt.Length - 1]);
//for (int i = 0; i < list.Count; i++)
//{
// Console.WriteLine(list[i]);
//}
//Console.ReadKey();
#endregion
#endregion
#region 制作一个控制台小程序。要求:用户可以在控制台录入每个学生的姓名,当用户输入quit(不区分大小写)时,程序停止接受用户的输入,并且显示出用户输入的学生的个数,以及每个学生的姓名。再增加一个显示姓“王”的同学的个数,此处不考虑复姓问题。
//List<string> strList = new List<string>();
////统计姓王的同学的个数
//int count = 0;
//string name;
//do
//{
// Console.WriteLine("请输入学生姓名:");
// name = Console.ReadLine();
// strList.Add(name);
// //如果名字中第一个字符是王
// if (name.IndexOf('王') == 0)
// {
// count++;
// }
//}
//while (name.ToLower() != "quit");
////去掉quit
//strList.RemoveAt(strList.Count - 1);
//Console.WriteLine("您一共录入{0}个学生,姓王同学的个数为:{1},名字分别为:", strList.Count,count);
//foreach (string strName in strList)
//{
// Console.WriteLine(strName);
//}
//Console.ReadKey();
#endregion
#region 将普通日期格式:“2011年6月4日” 转换成汉字日期格式:“二零一一年六月四日”。暂时不考虑10日、13日、23日等“带十”的问题。
//while(true)
//{
// Console.WriteLine("请输入一个日期:");
// string date = Console.ReadLine();
// date = ConvertData(date);
// Console.WriteLine(date);
// Console.ReadKey();
//}
#endregion
}
/// <summary>
/// 将普通日期格式转换成汉字日期格式
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
private static string ConvertData(string date)
{
//不能直接修改字符串,比如data[0]='零',字符串具有不可变性
//先根据字符串data生成一个char数组(字符数组)
char[] chs = date.ToCharArray();
for (int i = 0; i < chs.Length; i++)
{
switch(chs[i])
{
case '0':chs[i] = '零';
break;
case '1':
chs[i] = '一';
break;
case '2':
chs[i] = '二';
break;
case '3':
chs[i] = '三';
break;
case '4':
chs[i] = '四';
break;
case '5':
chs[i] = '五';
break;
case '6':
chs[i] = '六';
break;
case '7':
chs[i] = '七';
break;
case '8':
chs[i] = '八';
break;
case '9':
chs[i] = '九';
break;
}
}
//return date;
//将char数组转化为字符串string
return new string(chs);
}
}
}
阅读全文
0 0
- C#练习——统计整型数组中不重复数字的个数、将普通日期格式转换成汉字日期格式、在控制台录入每个学生的姓名,当用户输入quit(不区分大小写)时,程序停止接受用户的输入,并且显示出用户输入的学生的个数
- 输入一组数字,要求按回车则停止输入,并且统计出输入数字的个数
- C#控制台 统计用户输入的一串数字中每个数字出现的次数
- 2 编写一个应用程序,用户分别从两个文本框输入学生的姓名和分数,程序按成绩排序将这些学生的姓名和分数显示在一个文本区中。 程序运行效果如图:
- 根据用户输入类型进行格式转换的输入程序
- 不断用户输入一个数字(假定用户输入的为正整数),当用户输入"end"时显示刚才输入的数字中最大的值
- 用户输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- Java集合框架上机练习题(泛型、JFrame)用户分别从两个文本框输入学术的姓名和分数,程序按成绩排序将这些学生的姓名和分数显示在一个文本区中。
- (NumberFormatException数字格式异常)编写一个程序,提示用户读取两个整数,然后显示他们的和。程序应该在输入不正确时提示用户再次输入数字。
- 接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写
- 接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。
- 编写一个应用程序,用户分别从两个文本框输入学术的姓名和分数,程序按成绩排序将这些学生的姓名和分数显示在一个文本区中。 程序运行效果如图:
- .让用户输入一个日期格式如“2008/08/08”,将 输入的日期格式转换为“2008年-8月-8日”。
- 从控制台接受用户输入的信息
- C#面试题统计用户输入的一串数字中每个数字出现的次数
- 华为计算字符个数写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。
- 编写一个应用程序,用户分别从两个文本框输入学术的姓名和分数,程序按成绩排序将这些学生的姓名和分数显示在一个文本区中
- 编写一个应用程序,用户分别从两个文本框输入学术的姓名和分数,程序按成绩排序将这些学生的姓名和分数显示在一个文本区中。
- spring中添加定时任务的bean
- 唯一分解定理
- spring aop实现--注解实现和配置实现
- excel入门,如何玩转excel,你早该这么玩Excel笔记6
- linux C++ make 实战--建立一个最简单的工程
- C#练习——统计整型数组中不重复数字的个数、将普通日期格式转换成汉字日期格式、在控制台录入每个学生的姓名,当用户输入quit(不区分大小写)时,程序停止接受用户的输入,并且显示出用户输入的学生的个数
- HDU 1094
- JNotify文件夹监管
- if语句后面的分号
- 2724: [Violet 6]蒲公英
- 动态规划、记忆化搜索:HDU1505-City Game(记忆化搜索)
- MyBatis入门基础(一)
- springboot (1) 快速搭建简单项目
- arcengine栅格渲染(栅格重分类) IRasterClassifyColorRampRenderer