当前位置:网站首页>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);
边栏推荐
- MATLAB signal processing [Q & A essays · 2]
- List. How to achieve ascending and descending sort() 2020.8.6
- Sequence of entity layer, Dao layer, service layer and controller layer
- Summary of common methods of object class (September 14, 2020)
- ROS2专题(03):ROS1和ROS2的区别【01】
- Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
- Illegal behavior analysis 1
- Ros2 topic (03): the difference between ros1 and ros2 [02]
- 做自媒体视频剪辑怎么赚钱呢?
- Add data analysis tools in Excel
猜你喜欢
三问TDM
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
LM12丨Rolling Heikin Ashi二重K线滤波器
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
MATLAB signal processing [Q & A essays · 2]
SAP 内存参数调优过程
Unity3d learning notes 5 - create sub mesh
S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
ROS2专题(03):ROS1和ROS2的区别【01】
随机推荐
Explain
Entity层、DAO层、Service层、Controller层 先后顺序
Open source hardware small project: anxinco esp-c3f control ws2812
8.31 Tencent interview
[stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
统计电影票房排名前10的电影并存入还有一个文件
系统架构设计师备考经验分享:论文出题方向
LDO穩壓芯片-內部框圖及選型參數
Caip2021 preliminary VP
HDU 4747 mex "recommended collection"
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
在软件工程领域,搞科研的这十年!
B_ QuRT_ User_ Guide(40)
USB (XVIII) 2022-04-17
Cloud native data warehouse analyticdb MySQL user manual
违法行为分析1
Sequence of entity layer, Dao layer, service layer and controller layer
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
Fibonacci number of dynamic programming
Coreseek: the second step is index building and testing