简体   繁体   中英

Trying to make it every 5th token

Trying to print first token then every 5th after. has error not a statement

for (x = 0; x <= secretWord.length(); x + 5)
        {
            //Print
            System.out.println(tokens[x]);
        }
  • You've not initialized x
  • You can't have an expression dangling in the for-loop . You need to assign it to the variable x to make sense. Something like x = x + 5
  • Your condition is wrong x >= secretWord.length() . It should be x <= secretWord.length(); else your loop will not pass the first check and will never execute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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