首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

大神们。

2013-03-28 
大神们求助。。。为什么这段代码if条件进不去啊!!!理论上来说是应该进去的啊,困惑中。。跪求各位路过的大神们指

大神们求助。。。
为什么这段代码if条件进不去啊!!!
理论上来说是应该进去的啊,困惑中。。跪求各位路过的大神们指导~
using System;大神们。
using System.Collections.Generic;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string test = Console.ReadLine();
            string o = Console.ReadLine();
            int K = Convert.ToInt32(o);
            int n = test.Length;
            for (int i = n; i > 2*n; i++) {
                if (i - K < n)
                {
                    Console.Write(test[i - K]);
                }
                else
                {
                    Console.Write(test[i - n - K]);
                }
            }
        }
    }
}

Ps:这段代码是为了让字符串右移k位输出。。。
string
[解决办法]
首先for循环就进不去吧
for (int i = n; i > 2*n; i++) 

i>2*n能成立吗,除非n为负数,但实际n是test的长度,不可能为负数,所以你for循环根本进不去
是不是方向写反了,应该是
 for (int i = n; i < 2*n; i++) {
[解决办法]
 i > 2*n 
你觉这条能执行吗?
[解决办法]
int i = n; i > 2*n;
= =!

热点排行