c夏普语言输入方法,c sharp 的输入,输入,switch语句。

创建一个控制台应用程序,从键盘输入一个小写字母,要求输出该小写字母,其对应的大写字母,以及值。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("put small char:");

char ch1 =Convert.ToChar( Console.ReadLine());

while (!(ch1 >= 'a' && ch1 <= 'z'))

{

Console.WriteLine("put small char:");

ch1 = Convert.ToChar(Console.ReadLine());

}

char ch2=(char)(ch1-('a'-'A'));

Console.WriteLine("{0},{1},{2}", ch1, ch2, (int)ch1);

}

}

}

put small char:

a

a,A,97

请按任意键继续. . .

创建一个控制台程序,随机产生二个小数,计算它们对应的和,商,差,积。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

Random random = new Random();

double a = random.NextDouble() * 1000; //生成0-1000之间的随机小数。

double b = random.NextDouble() * 100; //生成0-100之间的随机小数。

Console.WriteLine("a={0} ,b={1}", a, b);

Console.WriteLine("a+b={0}", caculat(a, b,'+'));

Console.WriteLine("a-b={0}", caculat(a, b, '-'));

Console.WriteLine("a*b={0}", caculat(a, b, '*'));

Console.WriteLine("a/b={0}", caculat(a, b, '/'));

}

static double caculat(double a, double b,char operate)

{

double end = 0;

switch (operate)

{

case '+':

end = a + b;

break;

case '-':

end = a - b;

break;

case '*':

end = a * b;

break;

case '/':

end = a / b;

break;

default:

Console.WriteLine("has error");

break;

}

return end;

}

}

}

a=699.086446174926 ,b=39.3562914055569

a+b=738.442737580483

a-b=659.73015476937

a*b=27513.4498933355

a/b=17.7630163109378

请按任意键继续. . .

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值