当前位置:网站首页>C number of words, plus ¥, longest word, average value
C number of words, plus ¥, longest word, average value
2022-07-07 23:33:00 【Bobo in summer】
static int count(string sentence)
{
int count = 0;
string[] words = new string[100];
words = sentence.Split(' ');
for (int i = 0; i < words.Length; i++)
{
if (words[i] != "")
count++;
}
return count;
}
string sent = Console.ReadLine(); ;
Console.WriteLine("{0} There's something in it {1} Word ", sent, count(sent));
public static string AddDollar(string sentence)
{
string st = string.Empty;
for (int i = 0; i < sentence.Length; i++)
{
if (char.IsLetter(sentence[i]))
{
st += sentence[i] + "$";
}
else
{
st += sentence[i];
}
}
return st;
}
string st = Console.ReadLine();
Console.WriteLine(" Add ¥ The result is {0}", AddDollar(st));
Find the longest word
static string getLongWord(string sentense)
{
string word = "";
string[] words = new string[100];
words = sentense.Split(' ');
for (int i = 0; i < words.Length; i++)
{
if (word.Length < words[i].Length)
{
word = words[i];
}
}
return word;
}
string st = Console.ReadLine();
Console.WriteLine(" The longest word is :{0}", getLongWord(st));
public static void getMaxMinAverSum(out int max, out int min, out double aver, out int sum)
{
int[] nums = new int[10];
max = 0;
min = 50;
sum = 0;
Random rnd = new Random();
for (int i = 0; i < nums.Length; i++)
{
nums[i] = rnd.Next(20, 51);
if (max < nums[i])
max = nums[i];
if (min > nums[i])
min = nums[i];
sum += nums[i];
Console.Write("{0},", nums[i]);
}
aver = (double)sum / nums.Length;
}
int max, min, sum;
double aver;
getMaxMinAverSum(out max, out min, out aver, out sum);
Console.WriteLine(" Maximum {0}, minimum value {1}, Average {2}, and {3}", max, min, aver, sum);
边栏推荐
- Windows set redis to start automatically
- Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
- USB (XV) 2022-04-14
- LeeCode -- 6. Z 字形变换
- 系统设计概述
- 移动端异构运算技术 - GPU OpenCL 编程(基础篇)
- Ros2 topic (03): the difference between ros1 and ros2 [01]
- The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
- Unity3d Learning Notes 6 - GPU instantiation (1)
- 深入理解Mysql锁与事务隔离级别
猜你喜欢
How to change the formula picture in the paper directly into the formula in word
经纬度PLT文件格式说明
三问TDM
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
B_ QuRT_ User_ Guide(36)
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
PCB wiring rules of PCI Express interface
Three questions TDM
Right click the idea file to create new. There is no solution to create new servlet
深入理解Mysql锁与事务隔离级别
随机推荐
UE4_ Ue5 panoramic camera
B_ QuRT_ User_ Guide(38)
SAP HR奖罚信息导出
The text editor of markdown class should add colors to fonts (including typora, CSDN, etc.)
伸展树(一) - 图文解析与C语言实现
Coreseek: the second step is index building and testing
USB (XVII) 2022-04-15
VS扩展工具笔记
List. How to achieve ascending and descending sort() 2020.8.6
PCB wiring rules of PCI Express interface
深入理解Mysql锁与事务隔离级别
SAP HR 社会工作经历 0023
Design and implementation of spark offline development framework
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
JS get the key and value of the object
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
2021icpc Shanghai h.life is a game Kruskal reconstruction tree
HDU 4747 Mex「建议收藏」
SAP HR 家庭成员信息
Freelink open source call center design idea