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. 位于0/nut文件里的'Calculated'边界条件是什么意思?【翻译】

    翻译自:CFD-online 帖子地址:http://www.cfd-online.com/Forums/openfoam-pre-processing/140984-what-does-calcul ...

  2. 【零基础】神经网络优化之Adam

    一.序言 Adam是神经网络优化的另一种方法,有点类似上一篇中的“动量梯度下降”,实际上是先提出了RMSprop(类似动量梯度下降的优化算法),而后结合RMSprop和动量梯度下降整出了Adam,所以 ...

  3. javascript的正则表达式总结

    网上正则表达式的教程够多了,但由于javascript的历史比较悠久,也比较古老,因此有许多特性是不支持的.我们先从最简单地说起,文章所演示的正则基本都是perl方式. 元字符 ( [ { \ ^ $ ...

  4. 使用多个tomcat如何修改端口号

    一.找到tomcat下conf文件夹下server.xml: 二.修改8080端口 三.修改8009端口 四.修改8005端口 修改后同时启动多个tomcat成功.

  5. Cesium的Property机制总结

    前言 Cesium官方教程中有一篇叫<空间数据可视化>(Visualizing Spatial Data).该文文末简单提到了Cesium的Property机制,然后话锋一转,宣告此教程的 ...

  6. 简易的CRM系统案例SpringBoot + thymeleaf + MySQL + MyBatis版本

    创建maven项目 pop.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns ...

  7. Qt编写自定义控件43-自绘电池

    一.前言 到了9102年了,现在智能手机不要太流行,满大街都是,甚至连爷爷奶奶级别的人都会用智能手机,本次要写的控件就是智能手机中的电池电量表示控件,采用纯painter绘制,其实也可以采用贴图,我估 ...

  8. confluent kafka connect remote debugging

    1. Deep inside of kafka-connect start up To begin with, let's take a look at how kafka connect start ...

  9. LeetCode_118. Pascal's Triangle

    118. Pascal's Triangle Easy Given a non-negative integer numRows, generate the first numRows of Pasc ...

  10. vue-slicksort拖拽组件

    vue-slicksort拖拽组件 安装 通过npm安装 $ npm install vue-slicksort --save 通过yarn安装 $ yarn add vue-slicksort 插件 ...