c# - 如何计算控制台的输出
问题描述
这是一个评分标记表代码,我正在寻找应用程序如何计算一个字符串(例如:等级为 A)重复的次数。谢谢!此代码示例是我需要从中计算字符串的部分
if (p > 60 && p <= 80)
{
Console.WriteLine("Grade is A");
}
if (p > 80 && p <= 100)
{
Console.WriteLine("Grade is A++");
}
Console.ReadLine();
解决方案
这个想法是每次打印 A 时简单地增加一个整数变量。
以您的代码为基础的示例:
// Use a Variable that you increase in value
// To see how many A were printed
int acount = 0;
// Is number bigger than 60 and smaller or equal to 80
if (p > 60 && p <= 80)
{
Console.WriteLine("Grade is A");
acount++;
}
// If the first statement is true the second can't be true anyway
// so use else if so it doesn't have to make usless checks
// Is number bigger than 80 and smaller or equal to 100
else if (p > 80 && p <= 100)
{
Console.WriteLine("Grade is A++");
acount++;
}
// Print out result
Console.WriteLine("A was printed: " + acount + " times");
Console.ReadLine();
推荐阅读
- php - eks 集群中的缓慢 wordpress
- reactjs - React - API 数据仅在我手动刷新页面时显示
- html - 在 PHP 日志中找不到 favicon-96x96.png 错误的路由
- php - Laravel $request->input() 正在获取 url 路径以及查询参数名称
- kubernetes - 如何使用脚本增加 Kubernetes 集群中的有状态应用程序的负载
- tesseract - 用tesseract识别淡线
- github-cli - 如何捕获 github-cli pr 列表
- python - if 语句删除和替换字符串
- javascript - Vue.js。几个带js的类
- haskell - (map .filter)的通用类型