| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 663 人关注过本帖
标题:请帮我改正下错误
只看楼主 加入收藏
l7556950
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-10-5
收藏
 问题点数:0 回复次数:3 
请帮我改正下错误
下面的代码该怎样改正。搞了半天都不懂。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 函数对比大小值
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int k =minnum(a, b); //就这里有问题
            Console.WriteLine(k);
        }

        int minnum(int a, int b)
        {
            int c = 0;
            if (a > b)
            {
                c =b;
            }
            else if (a < b)
            {
                c =a;
            }
            return c;
        }
    }
}
搜索更多相关主题的帖子: class using 
2011-10-05 00:20
q332010372
Rank: 2
等 级:论坛游民
帖 子:52
专家分:61
注 册:2010-7-27
收藏
得分:0 
程序代码:
static int minnum(int a, int b)
        {
            int c = 0;
            if (a > b)
            {
                c = b;
            }
            else if (a < b)
            {
                c = a;
            }
            return c;
        }
       
         static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int k = minnum(a, b);
            Console.WriteLine(k);
             Console.ReadKey();
        }       
        
或者
程序代码:
  int minnum(int a, int b)
        {
            int c = 0;
            if (a > b)
            {
                c = b;
            }
            else if (a < b)
            {
                c = a;
            }
            return c;
        }
       
         static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int k =new Program().minnum(a, b);
            Console.WriteLine(k);
             Console.ReadKey();
        }       
        




2011-10-05 01:50
l7556950
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-10-5
收藏
得分:0 
谢谢。
2011-10-05 01:57
serious
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:81
专家分:497
注 册:2009-8-18
收藏
得分:0 
此外,当a=b时,c是0。
你应该写:

程序代码:
static int minnum(int a, int b)
{
    int c = 0;
    if (a >= b)
    {
        c = b;
    }
    else if (a < b)
    {
        c = a;
    }
    return c;
}

或者:

static int minnum(int a, int b)
{
    return a <= b ? a : b;
}

2011-10-05 05:37
快速回复:请帮我改正下错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012231 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved