Help on command processor program!!!

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Help on command processor program!!!

  1. #1
    Join Date
    Apr 2004

    Help on command processor program!!!

    Hi guys I'm a noobie to Java and need some help with writing 4 small functions in my command processor program.

    My "reversethm" function compiles but gets a weird error when i type "java doit reverse one two three" (supposed to give me back three two one).

    The "findlongest" should make the program print out the argument that is the longest (i.e., contains the most characters). If more than one argument are of equal length, it doesn't matter which is printed out. BUT I'm having trouble with it because I don't know how to count characters instead of the whole word...

    The findnth command is followed by a number, and then some arguments. It should print out the argument corresponding to the number. The program should print out a warning message if nothing follows the nth command, or if there aren't enough arguments following the number. Need help no idea how to get started on this one.

    This is what I have so far
    class doit { 
      // auxiliary functions here
      public static void findnth (String[] args) {
      public static void findlongest (String[] args) {
        int i;
        String templong = args[1];
        for (i = 2; i < args.length; ++i) {
          //if (args[i].length > templong.length)  <- need to find a way to count the number of characters
            templong = args[i];
      public static void reversethem (String[] args) {
        int i;
        for (i = args.length; i > 1 ; --i) {
      public static void echothem (String[] args) {
        int i;
        for (i = 1; i < args.length ; ++i) {
      public static void  behelpful () {
        System.out.println("Commands: help echo nth longest sort reverse"); 
     public static void main (String[] args) { 
       if (args.length==0) behelpful(); 
       else if (args[0].equals("echo")) echothem(args); 
       else if (args[0].equals("help")) behelpful();
       else if (args[0].equals("nth")) findnth(args);
       else if (args[0].equals("longest")) findlongest(args);
       else if (args[0].equals("reverse")) reversethem(args);
       else {
         System.out.println ("Unknown command: "+args[0]);

    Thanks for your time guys!

  2. #2
    Join Date
    Apr 2004
    please help!! In desperate state!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center