新手求大神,有其他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 ...
随机推荐
- JIRA项目跟踪管理工具简介与安装
1.什么是JIRA JIRA是Atlassian公司出品的项目与事务跟踪工具,被广泛应用于缺陷跟踪.客户服务.需求收集.流程审批.任务跟踪.项目跟踪和敏捷管理等工作领域. Atlassian2002年 ...
- poj 2975 Nim_最经典的Nim取石子
题意:给你n堆石头,每次只能在一堆取最少一个石子,最后拿走最后一堆的为胜者,问胜者有多少种赢得取法 #include <iostream> #include<cstdio> u ...
- Longest Substring Without Repeating Characters 最长不重复子串
只遍历一次字符串即可求出最长不重复子串的长度. int lengthOfLongestSubstring(string s) { vector<,-); //记录字符上一次出现的位置,ASCII ...
- Android的Activity切换动画特效库SwitchLayout,视图切换动画库,媲美IOS
由于看了IOS上面很多开发者开发的APP的视图界面切换动画体验非常好,这些都是IOS自带的,但是Android的Activity等视图切换动画并没有提供原生的,所以特此写了一个可以媲美IOS视图切换动 ...
- 创建渐进式jpeg图片
<?php // Create an image instance $im = imagecreatefromjpeg('test.jpg'); // Enable interlancing ...
- Sumsets(3sum问题,枚举d,c二分a+b)
Sumsets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9997 Accepted: 2736 Descripti ...
- SQL Server中的sysobjects
摘自:http://www.cnblogs.com/bugY/archive/2011/09/21/2184182.html 关于SQL Server数据库的一切信息都保存在它的系统表格里.我怀疑你是 ...
- Net Configuration Assistant和Net Manager的区别
1.Net Configuration Assistant和Net Manager在oracle的配置工具中,Net Configuration Assistant(网络配置助手)和Net Manag ...
- java synchronized使用
java synchronized 基本上,所有并发的模式在解决线程冲突问题的时候,都是采用序列化共享资源的方案.这意味着在给定时刻只允许一个任务访问该资源.这个一般通过在代码上加一条锁语句实现,因为 ...
- [string]Roman to Integer,Integer to Roman
一.Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within ...