为什么这段代码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
理论上来说是应该进去的啊,困惑中。。跪求各位路过的大神们指导~
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 (int i = n; i > 2*n; i++) i>2*n能成立吗,除非n为负数,但实际n是test的长度,不可能为负数,所以你for循环根本进不去
是不是方向写反了,应该是
for (int i = n; i < 2*n; i++) {
你觉这条能执行吗?
= =!