zoukankan      html  css  js  c++  java
  • 写4个同名方法,实现两个整数、两个实数,一个实数一个整数,一个整数一个实数之间的求和。在主调函数中调用这4个方法计算相关的值。(方法的重载)

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace ConsoleApplication7
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             //整数相加
    14             int a = 1;
    15             int b = 3;
    16             int sum = Test(a, b);
    17             Console.WriteLine("整数相加:{0}+{1}={2}", a, b, sum);
    18             Console.WriteLine();
    19             //实数相加
    20             double c = 2.5;
    21             double d = 5.2;
    22             double sum1 = Test(c, d);
    23             Console.WriteLine("实数数相加:{0}+{1}={2}", c, d, sum1);
    24             Console.WriteLine();
    25             //实数加整数
    26             double e = 3.5;
    27             int f = 6;
    28             double sum2 = Test(e, f);
    29             Console.WriteLine("实数加整数:{0}+{1}={2}", e, f, sum2);
    30             Console.WriteLine();
    31             //整数加实数
    32             int g = 8;
    33             double h = 9.9;
    34             double sum3 = Test(g, h);
    35             Console.WriteLine("整数加实数:{0}+{1}={2}", g, h, sum3);
    36             Console.WriteLine();
    37 
    38             Console.ReadKey();
    39         }
    40 
    41         static int Test(int a, int b)
    42         {
    43             int sum = a + b;
    44             return sum;
    45         }
    46         static double Test(double a, double b)
    47         {
    48             double sum = a + b;
    49             return sum;
    50         }
    51         static double Test(double a, int b)
    52         {
    53             double sum = a + b;
    54             return sum;
    55         }
    56         static double Test(int a, double b)
    57         {
    58             double sum = a + b;
    59             return sum;
    60         }
    61     }
    62 }
  • 相关阅读:
    poj1014 Dividing (多重背包)
    HDOJ 1316 How Many Fibs?
    最大字串和
    WHY IE AGAIN?
    Codeforces Round #143 (Div. 2) (ABCD 思维场)
    自用组帧工具
    菜鸟学EJB(二)——在同一个SessionBean中使用@Remote和@Local
    shell 块注释
    检测到在集成的托管管道模式下不适用的 ASP.NET 设置的解决方法
    Windows Myeclipse 10 安装 Perl 插件
  • 原文地址:https://www.cnblogs.com/start-from-scratch/p/5058536.html
Copyright © 2011-2022 走看看