当前位置:网站首页>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);
边栏推荐
- Have all the fresh students of 2022 found jobs? Is it OK to be we media?
- 经纬度PLT文件格式说明
- IDEA 2021.3. X cracking
- Force deduction solution summary 648 word replacement
- 1. Sum of two numbers
- 云原生正在吞噬一切,开发者该如何应对?
- Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
- 建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
- Lm12 rolling heikin Ashi double K-line filter
- Markdown
猜你喜欢
随机推荐
SAP HR奖罚信息导出
windows设置redis开启自动启动
做自媒体视频剪辑怎么赚钱呢?
JS get the key and value of the object
Anxinco esp32-a1s development board is adapted to Baidu dueros routine to realize online voice function
Coreseek: the second step is index building and testing
Deep understanding of MySQL lock and transaction isolation level
SAP HR 劳动合同信息 0016
【7.5】15. 三数之和
leetcode-520. Detect capital letters -js
Unity3d learning notes 4 - create mesh advanced interface
v-for遍历对象
深入理解Mysql锁与事务隔离级别
Explain
re1攻防世界逆向
LeeCode -- 6. Z 字形变换
HDU 4747 mex "recommended collection"
三问TDM
Have all the fresh students of 2022 found jobs? Is it OK to be we media?
StringUtils工具类