简体   繁体   English

尝试每5个令牌赚取一次

[英]Trying to make it every 5th token

Trying to print first token then every 5th after. 尝试先打印令牌,然后再打印第5个令牌。 has error not a statement 有错误而不是陈述

for (x = 0; x <= secretWord.length(); x + 5)
        {
            //Print
            System.out.println(tokens[x]);
        }
  • You've not initialized x 您尚未初始化x
  • You can't have an expression dangling in the for-loop . 您不能在for-loop悬挂表达式。 You need to assign it to the variable x to make sense. 您需要将其分配给变量x才有意义。 Something like x = x + 5 x = x + 5类的东西
  • Your condition is wrong x >= secretWord.length() . 您的条件错误x >= secretWord.length() It should be x <= secretWord.length(); 它应该是x <= secretWord.length(); else your loop will not pass the first check and will never execute. 否则,您的循环将无法通过第一个检查,并且永远不会执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM