Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java - Printing arguments in reverse order

Options
  • 16-01-2004 2:11pm
    #1
    Closed Accounts Posts: 1,723 ✭✭✭


    Lads/Lassies,

    I'm sure this will be trivial, so i'd appreciate the help, i'm trying to learn a bit of java on my own

    What code do i need to print out command line arguments in reverse order.

    public class MyCode {
    public static void main (String [] args) {
    for (int i=0; i < args.length; i = i + 1)

    System.out.println ( args );
    }
    }

    Any help appreciated

    If anybody knows any handy sites for java let me know
    thanx


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Ah, you're almost there.

    The only thing you need to think of is that for each value of i from 0 to args.length, you're printing out the value in args.
    To print them out backwards all you need to do is alter the for() loop, so that i goes from args.length -1 down to 0.

    I'm intentionally not giving you the code btw ;)


  • Closed Accounts Posts: 1,723 ✭✭✭empirix


    Doh---I can't get this , I can't get this, I think I have done everything bar reverse them:mad:

    The memories are coming back to why i packed in programming after my diploma


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Just change your for loop to read

    for(int i = (args.length - 1); i >= 0; i--)

    :)


  • Closed Accounts Posts: 1,723 ✭✭✭empirix


    Thanx for that Seamus, I wouldn't of cracked that.
    I think I will have to hit the books or get a few grinds


Advertisement