1、开发一个控制台应用程序,根据提示从键盘获取一个华氏温度,请转换并输出对应的摄氏温度。

 using System;

 namespace Project
{
class Program
{
public static void Main(string[] args)
{ // 提示输入 Input
Console.WriteLine("请输入华氏温度"); //给分点 // 获取数据
string f = Console.ReadLine(); // 类型转化: string -> double
double F = Convert.ToDouble(f); //方法1 : 数据转换
double F_ = double.Parse(f); //方法2 : 类型解析,把基本类型看成类 if (true)
{
Console.WriteLine("请输入>0的华氏温度");
}
else
{
// 公式运算
double c = * (F - ) / ; // 输出 : output
// 中文就是"构造字符串"
Console.WriteLine("华氏温度为{0:f2},摄氏温度为:{1:f2}", c, F);
} }
}
}

华氏转摄氏


2、编写一个程序,从键盘输入一个x值,程序输出y的值。

   {  -1 + 2 * x   ,  x < 0

y =  { -1       ,  x = 0

   {  -1 + 3 * x  ,  x > 0

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace MyProject2
{
class Program
{
static void Main(string[] args)
{
// Input
Console.WriteLine("请输入一个x值");
string str_x = Console.ReadLine(); // change string -> double
double x = Convert.ToDouble(str_x);
double y; // compute
if (x < )
{
Console.WriteLine("x < 0 : y = -1 + 2x ");
y = - + * x;
}
else if (x == 0.0)
{
Console.WriteLine("x = 0 : y = -1 ");
y = -;
}
else
{
Console.WriteLine("x > 0 : y = -1 + 3x");
y = - + * x;
} //output
Console.WriteLine("x = {0:f2} , y = {1:f2}", x, y);
}
}
}

分段函数


3、在控制台中打印如下矩阵。

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace MyProject3
{
class Program
{
static void Main(string[] args)
{
for (int i = ; i <= ; i++)
{
Console.Write("{0,6}",i);
if (i % == )
{
Console.WriteLine();
}
}
}
}
}

打印矩阵


4、开发一个控制台应用程序,根据提示从键盘输入一个字符,判断此字符是数字、大写字母、小写字母还是其它字符。

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace MyProject4
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
char ch = Convert.ToChar(str);
if ( '' <= ch && ch <= '' )
{
Console.WriteLine("输入的为数字: {0}",ch);
}
else if ('a' <= ch && ch <= 'z')
{
Console.WriteLine("输入的为小写字母: {0}", ch);
}
else if ('A' <= ch && ch <= 'Z')
{
Console.WriteLine("输入的为大写字母: {0}", ch);
}
else
{
Console.WriteLine("输入的为其他字符: {0}", ch);
}
}
}
}

判断字符类型

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace MyProject
{
class Program
{
static void Main(string[] args)
{ Console.WriteLine("请输入一个字符");
int x = Console.Read();
char ch = (char)x;
string res = "";
if ( char.IsDigit(ch) )
{
res = "数字";
}
else if ( char.IsLower(ch) )
{
res = "小写字母";
}
else if ( char.IsUpper(ch) )
{
res = "大写字母";
}
else
{
res = "其他字符";
}
Console.WriteLine("{0} 是 {1}",ch,res);
}
}
}

利用静态方法判断

【C#】上机实验一的更多相关文章

  1. lingo运筹学上机实验指导

    <运筹学上机实验指导>分为两个部分,第一部分12学时,是与运筹学理论课上机同步配套的4个实验(线性规划.灵敏度分析.运输问题与指派问题.最短路问题和背包问题)的Excel.LONGO和LI ...

  2. 算法课上机实验(一个简单的GUI排序算法比较程序)

    (在家里的电脑上Linux Deepin截的图,屏幕大一点的话,deepin用着还挺不错的说) 这个应该是大二的算法课程上机实验时做的一个小程序,也是我的第一个GUI小程序,实现什么的都记不清了,只记 ...

  3. Java第一次上机实验源代码

    小学生计算题: package 第一次上机实验_; import java.util.*; public class 小学计算题 { public static void main(String[] ...

  4. oracle上机实验内容

    这是oracle实验的部分代码,我花了一中午做的. 第一次上机内容 实验目的:熟悉ORACLE11G的环境 实验内容: 第二次上机内容 实验目标:掌握oracle体系结构,掌握sqlplus的运行环境 ...

  5. 软件测试技术lab2——Selenium上机实验

    Selenium上机实验说明 1.安装SeleniumIDE插件 2.学会使用SeleniumIDE录制脚本和导出脚本 3.访问http://121.193.130.195:8080/使用学号登录系统 ...

  6. 合肥工业大学数据结构上机实验代码与实验报告(全)github地址

    我已经将这个学期的所有数据结构上机实验的代码与报告上传到github上了,一直都有这个想法,但没抽出时间来学习git.经过上周简单的练习后,我已经基本学会运营自己的代码仓库了.所有代码都是C++写的类 ...

  7. SDN第五次上机实验

    1.浏览RYU官网学习RYU控制器的安装和RYU开发入门教程,提交你对于教程代码的理解. 1.通过源码安装RYU控制器 sudo apt-get install python3-pip git clo ...

  8. 《Java语言程序设计》上机实验

    实验一   Java环境演练   [目的] ①安装并配置Java运行开发环境: ②掌握开发Java应用程序的3个步骤:编写源文件.编译源文件和运行应用程序: ③学习同时编译多个Java源文件. [内容 ...

  9. LAB2 软件测试 Selenium上机实验 2017

    1.安装SeleniumIDE插件 打开Firefox——>菜单栏——>附加组件——>获取附加组件——>查看更多附加组件——>搜索框输入SeleniumIDE并查找——& ...

  10. 【C#】上机实验二

    实验1: 求解 1/1 + 1 / 2  + 1 / 3  + 1 / 4 …… + 1 / i = ? 确保精度在 1e-6内. using System; using System.Collect ...

随机推荐

  1. meshing-三棱锥结构化网格

    原视频下载地址: https://yunpan.cn/cqcq2gE6Iy2P8  访问密码 7d5a ​

  2. GO 跟C++/C差异

    规范的语法(不需要符号表来解析) 垃圾回收(独有) 无头文件 明确的依赖 无循环依赖 常量只能是数字 int和int32是两种类型 字母大小写设置可见性(letter case sets visibi ...

  3. HearthBuddy 调试肯瑞托法师寒冰屏障的配合

    35疯狂的科学家 63肯瑞托法师 13过期货物专卖商 64对面的英雄术士 比较好的出牌策略是,肯瑞托法师+寒冰屏障 ailoop1 startEnemyTurnSimThread1start prin ...

  4. Linux中touch命令使用(创建文件)

    touch命令有两个功能: 1.用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来: 2.用来创建新的空文件. 语法 touch(选项)(参数) 选项 -a:或 ...

  5. Hallelujah Leonard Cohen

      Hallelujah 歌词   Leonard Cohen   Now I've heard there was a secret chord   我听说有一个隐秘的弦音   That David ...

  6. OpenJudge计算概论-细菌实验分组

    /*====================================================细菌实验分组总时间限制: 1000ms 内存限制: 65536kB描述有一种细菌分为A.B两 ...

  7. Civil 3D百度云地址

    Civil 3D 2018百度云地址 https://pan.baidu.com/s/1edeVhG Civil 3D 2019注册机百度云地址 链接: https://pan.baidu.com/s ...

  8. POPUP_GET_VALUES 金额字段不可编辑

    转自:https://blog.csdn.net/huanglin6/article/details/102733845 当在POPUP_GET_VALUES函数中参考的字段是个货币或者金额字段的话, ...

  9. svn如何撤销之前某个版本所做的改变

    撤销这个版本所做的修改:(撤销这个版本所做的修改) 右键项目svn->show log->revert changes from this revision 如果要恢复到某个版本:(这个版 ...

  10. query解决touchmove时屏蔽touchend

    var dragging = false; $("li").on("touchmove",function(){ dragging = true; }); $( ...