新手求大神,有其他swit-case的思路写这个程序么?
两个程序:
switch-case与if-else if的区别
相同点:可以实现多分支结构;
不同点:
switch:一般只能用于等值比较.(可以进行范围运算???---学会用switch计算范围出炉的思路____待解决)
if_else if:可以处理范围计算.
switch(变量)
{
case 变量:
break;
}
switch括号中的"变量"与case表达式中的"变量" 必须是同一类型,
或者是相兼容的数据类型.(一般是int类型或者string类型?).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 练习2
{
class Program
{
static void Main(string[] args)
{
//对成绩进行考核评级
Console.WriteLine("请输入你的成绩?");
int score = Convert.ToInt32(Console.ReadLine());
switch (score/)
{
case :
Console.WriteLine("A");
break;
case :
Console.WriteLine("A");
break;
case :
Console.WriteLine("B");
break;
case :
Console.WriteLine("C");
break;
case :
Console.WriteLine("D");
break;
default:
Console.WriteLine("E");
break;
}
Console.ReadKey();
}
}
}
总感觉这种方法有点绕思维,有可以直接判断的么?难道只能用if-else if来写么??? ↓↓↓
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace if_else_if写switch作业
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入你的成绩?");
int score = Convert.ToInt32(Console.ReadLine());
if (score >= )
{
Console.WriteLine("A"); }
else if (score >= )
{
Console.WriteLine("B");
}
else if (score >= )
{
Console.WriteLine("C");
}
else if (score >= )
{
Console.WriteLine("D");
}
else
{
Console.WriteLine("E");
} Console.ReadKey();
}
}
}
新手求大神,有其他swit-case的思路写这个程序么?的更多相关文章
- 自己封装了一个EF的上下文类.,分享一下,顺便求大神指点
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- [LeetCode]LRU Cache有个问题,求大神解答【已解决】
题目: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...
- 刚下了VS2010不会用,求大神指点迷津
刚下了VS2010不会用,求大神指点迷津 [菌菌][C语言MOOC]第七周计算分数精确值(10分) thinkphp3.1Calltoamemberfunctionget()onnull java提示 ...
- python 抓取搜狗微信出现的问题,求大神解决
爬取到的data不是想要获取文章页面的源码,而是跳转到验证码的页面的源码.我网上查了一下是由于访问过于频繁导致的,我也加了time.sleep和改了请求头但还是显示不了,求大神支招,除了识别验证码的方 ...
- debug的粗略使用(求大神们补充、指教,小渣马上改)
debug的使用 往往我们在写代码的时候会发现那种很隐秘的bug,一直找找不多,甚至开始怀疑人生.目光扫描和人脑编译又耗时又耗精力又很容易中途乱了脑子,一切得重新来,所以我写了一篇博客来模拟一下检查b ...
- 真想用c#开发个 wp五笔输入法。。。奈何网上资料太少,源码都是c++写的。求大神指点!!!
真想用c#开发个 wp五笔输入法...奈何网上资料太少,源码都是c++写的.求大神指点!!!!
- c# winfrom 页面的enter变为tab 功能使用 在特定的按钮里面如何继续当enter使用求大神帮忙解答一下 !!急
enter 当tab 键用 已经实现 :例如按回车的时候切换一直走 ,走到一个按钮如何让回车键在这个按钮的时候还是执行enter按钮的功能而不是tab 求大神解答一下, 目前页面tab功能改为 ...
- iis频繁奔溃,求大神帮忙分析dump
直接上图了 上图三个错误最近频繁出现,出现一次iis就奔溃一次,抓取的dump分析后如下: Couldn't resolve error at 'ls' :> !analyze -v ***** ...
- 读FCL源码系列之List<T>---让你知其所以然---内含疑问求大神指点
序言 在.NET开发中,List<T>是我们经常用到的类型.前段时间看到其他部门小伙伴讨论“两个List(10W个元素)集合求并集,list1.Where(p=>list2.Cont ...
随机推荐
- atomic_compare_exchange
atomic_compare_exchange 分为两个版本 atomic_compare_exchange_strong 和 atomic_compare_exchange_weak,语义如下 bo ...
- 这是一个hibernate 联合主键的例子
package com.bird.entity; import java.io.Serializable; import javax.persistence.Entity; import javax. ...
- OpenStack Block Storage安装配置use LVM
1,storage systems use LVM Ins and configuration Block Storage; apt-get install lvm2; 创建Physical volu ...
- Longest Substring Without Repeating Characters 最长不重复子串
只遍历一次字符串即可求出最长不重复子串的长度. int lengthOfLongestSubstring(string s) { vector<,-); //记录字符上一次出现的位置,ASCII ...
- wxpython 拖放
拖放对用户是非常直观.它在许多桌面应用程序,用户可以复制或只需用鼠标拖动和删除另一个窗口中移动对象从一个窗口到另一个中. 拖放操作包括以下步骤 - 声明拖放目标 创建数据对象 创建 wx.DropSo ...
- Baby Ming and Matrix games(dfs计算表达式)
Baby Ming and Matrix games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- iOS 四种延时的方法
- (void)initBlock{ //延时的方法 //1:GCD延时 此方式在能够在參数中选择运行的线程. 是一种非堵塞的运行方式,没有找到取消运行的方法. double ...
- HTML5新特性学习-2
本文在于巩固基础 HTML5绘图基础 <canvas>画布元素的使用 <div> <canvas id="can" width="200px ...
- random background
function roll(){ var bg = document.getElementById("loginbg"); var rnd = Math.floor(Math.ra ...
- MD5校验
好久没有写随笔了,正好这两天可以休整一下,借此机会总结下最近使用python的小体会. 个人体会文件校验在下载文件时使用较多,在linux下最简单的实现方式就是: 1 $ md5sum filenam ...