【C#】上机实验一
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#】上机实验一的更多相关文章
- lingo运筹学上机实验指导
<运筹学上机实验指导>分为两个部分,第一部分12学时,是与运筹学理论课上机同步配套的4个实验(线性规划.灵敏度分析.运输问题与指派问题.最短路问题和背包问题)的Excel.LONGO和LI ...
- 算法课上机实验(一个简单的GUI排序算法比较程序)
(在家里的电脑上Linux Deepin截的图,屏幕大一点的话,deepin用着还挺不错的说) 这个应该是大二的算法课程上机实验时做的一个小程序,也是我的第一个GUI小程序,实现什么的都记不清了,只记 ...
- Java第一次上机实验源代码
小学生计算题: package 第一次上机实验_; import java.util.*; public class 小学计算题 { public static void main(String[] ...
- oracle上机实验内容
这是oracle实验的部分代码,我花了一中午做的. 第一次上机内容 实验目的:熟悉ORACLE11G的环境 实验内容: 第二次上机内容 实验目标:掌握oracle体系结构,掌握sqlplus的运行环境 ...
- 软件测试技术lab2——Selenium上机实验
Selenium上机实验说明 1.安装SeleniumIDE插件 2.学会使用SeleniumIDE录制脚本和导出脚本 3.访问http://121.193.130.195:8080/使用学号登录系统 ...
- 合肥工业大学数据结构上机实验代码与实验报告(全)github地址
我已经将这个学期的所有数据结构上机实验的代码与报告上传到github上了,一直都有这个想法,但没抽出时间来学习git.经过上周简单的练习后,我已经基本学会运营自己的代码仓库了.所有代码都是C++写的类 ...
- SDN第五次上机实验
1.浏览RYU官网学习RYU控制器的安装和RYU开发入门教程,提交你对于教程代码的理解. 1.通过源码安装RYU控制器 sudo apt-get install python3-pip git clo ...
- 《Java语言程序设计》上机实验
实验一 Java环境演练 [目的] ①安装并配置Java运行开发环境: ②掌握开发Java应用程序的3个步骤:编写源文件.编译源文件和运行应用程序: ③学习同时编译多个Java源文件. [内容 ...
- LAB2 软件测试 Selenium上机实验 2017
1.安装SeleniumIDE插件 打开Firefox——>菜单栏——>附加组件——>获取附加组件——>查看更多附加组件——>搜索框输入SeleniumIDE并查找——& ...
- 【C#】上机实验二
实验1: 求解 1/1 + 1 / 2 + 1 / 3 + 1 / 4 …… + 1 / i = ? 确保精度在 1e-6内. using System; using System.Collect ...
随机推荐
- [后渗透]Linux下的几种隐藏技术【转载】
原作者:Bypass 原文链接:转自Bypass微信公众号 0x00 前言 攻击者在获取服务器权限后,会通过一些技巧来隐藏自己的踪迹和后门文件,本文介绍Linux下的几种隐藏技术. 0x01 隐藏文件 ...
- Redis企业实战的一些坑
附录:Redis企业实战的一些坑 一.前言 小伙伴们对Redis应该不陌生,Redis是系统必备的分布式缓存中间件,主要用来解决高并发下分担DB资源的负载,从而提升系统吞吐量. Redis支持多种数据 ...
- shell 脚本 - 关于循环的应用
array=('Brand' 'BrandInfo' 'BrandBaojia' 'VehicleType' 'BrandBaoyang' 'Youhui' 'Config' \ 'Comment' ...
- web框架性能点
awesome-go-web-frameworks/README.md at master · speedwheel/awesome-go-web-frameworkshttps://github.c ...
- this.getClass()和super.getClass()得到的是同一个类
今天dubug代码时发现this.getClass()和super.getClass()得到的竟然是同一个类,都是当前类. 遍访网络资料得出: getClass()不受this和super影响,而是有 ...
- pytorch常用normalization函数
参考:https://blog.csdn.net/liuxiao214/article/details/81037416 归一化层,目前主要有这几个方法,Batch Normalization(201 ...
- 总结Lock和synchronized的区别
1. Lock是一个接口,而synchronized是Java中的关键字,synchronized是内置的语言实现,Lock是代码层面的实现. 2. Lock可以选择性的获取锁,如果一段时间获取不到, ...
- java递归删除目录下所有内容
java递归删除目录下所有内容 private static boolean deleteDir(File dir) {if (dir.isDirectory()) { String[] ...
- CentOS7下搭建zabbix监控(二)——Zabbix被监控端配置
Zabbix监控端配置请查看:CentOS7下搭建zabbix监控(一)——Zabbix监控端配置 (1).在CentOS7(被监控端)上部署Zabbix Agent 主机名:youxi2 IP地址: ...
- python中os.popen, os.system()区别
直接上个例子吧,注意结果,os.system的结果只是命令执行结果的返回值,执行成功为0: >>> a=os.system('ls') Applications Movies pyt ...