| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 692 人关注过本帖
标题:比较两个相同的字符数组
只看楼主 加入收藏
白5130
Rank: 2
等 级:论坛游民
威 望:1
帖 子:26
专家分:17
注 册:2013-4-13
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:1 
比较两个相同的字符数组
using System;
namespace Compare_array
{
    class Compare_array
    {
        static void Main(string[] args)
        {
            int i, flag = 1;
            char[] str1 = new char[3];
            char[] str2 = new char[3];
            Console.WriteLine("Enter the first string of length five");
            str1 = Console.ReadLine().ToCharArray();
            Console.WriteLine("Enter the second string of length five");
            str2 = Console.ReadLine().ToCharArray();
            for (i = 0; i <= 2; i++)
            {
                if (str1[i] != str2[i])
                {
                    flag = 0;
                    break;
                }
                if (flag == 1)
                {
                    Console.WriteLine("The strings are identical");
                }
                else
                {
                    Console.WriteLine("The strings are not identical");
                }
            }
        }
    }
}
输入的str1为 a b c;  str2为 a c b;那为什么会输出两次 The strings are identical b 与 c 不是不相同的吗?那么应该就跳出循环,只输出一次The strings are identical 还请前辈指点
搜索更多相关主题的帖子: namespace static second Enter 
2013-05-22 22:55
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:20 
a空格b空格c
a空格c空格b

a相同
第一个空格相同
2013-05-23 00:56
快速回复:比较两个相同的字符数组
数据加载中...
 
   



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

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