11.方法的练习

练习1:

   
  1. namespace _20.方法的练习01
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //读取输入的整数,定义成方法,多次调用
  8. //(如果用户输入的是数字,则返回,否则提示用户重新输入)
  9. Console.WriteLine("请输入数字:");
  10. string number = Console.ReadLine();
  11. number=ReadInput(number);
  12. Console.WriteLine(number);
  13. Console.ReadKey();
  14. }
  15. public static string ReadInput(string input)
  16. {
  17. double number = 0;
  18. if (double.TryParse(input, out number))
  19. {
  20. return number.ToString();
  21. }
  22. else
  23. {
  24. return "你输入的不是数字请重新输入!";
  25. }
  26. }
  27. }
  28. }

练习2:

   
  1. namespace _21.方法的练习02
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //查找出入的两个数中的最大值
  8. Console.WriteLine("请输入数1:");
  9. string a1 = Console.ReadLine();
  10. double d1 = double.Parse(a1);
  11. string a2 = Console.ReadLine();
  12. double d2 = double.Parse(a2);
  13. double max=Max(d1, d2);
  14. Console.WriteLine("最大数是:{0}",max);
  15. Console.ReadKey();
  16. }
  17. public static double Max(double a, double b)
  18. {
  19. if (a > b)
  20. {
  21. return a;
  22. }
  23. else
  24. {
  25. return b;
  26. }
  27. }
  28. }
  29. }





转载于:https://www.cnblogs.com/HelloZyjS/p/6023204.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值