Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java - Printing arguments in reverse order

  • 16-01-2004 02: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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 Posts: 68,173 ✭✭✭✭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