For loop for multiple arguments

Discussion in 'Plugin Development' started by Gecco1234, May 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Gecco1234

    My for loop for multiple arguments isn't working.
    It does the 2nd argument as the first and second.
    Code:java
    1. StringBuilder message = new StringBuilder(args[0]);
    2. for (int arg = 1; arg == args.length; arg++) {
    3. message.append(" ").append(args[arg]);
    4. }

    But works for 3rd 4th argument etc.
     
  2. Offline

    coasterman10

    You should use arg < args.length instead of what you have currently in the for loop line.
     
  3. Offline

    Gecco1234

    Still dosn't work :/
     
  4. Offline

    ThunderWaffeMC

    Also you should start at 0 instead of 1.
     
  5. Offline

    Arfie99

    ThunderWaffeMC nope, he adds the first argument already when initializing the StringBuilder.

    Gecco1234 Could you try this?
    Code:java
    1. StringBuilder message = new StringBuilder();
    2. for(String arg : args){
    3. message.append(arg).append(" ");
    4. }
     
  6. Offline

    coasterman10

    ThunderWaffeMC No, he already added the first argument to the StringBuilder.
     
  7. Offline

    Gecco1234

    Works Thanks!
     
Thread Status:
Not open for further replies.

Share This Page