Results 1 to 3 of 3

Thread: Small problem

  1. #1
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default Small problem

    i have this programme when i compile it i get that message so how could i solve that problem because it is first time i get this message when i compile it i donít know how to solve it this is the message that i get it (error: a single integer argument needed)

    class hanoi
    {
    public static void main (String args[])
    {
    if (args.length != 1) {
    System.err.println("error: a single integer argument needed");
    System.exit(1);
    }
    Integer N = new Integer(args[0]);
    H_dohanoi(N.intValue(), 3, 1, 2);
    System.exit(0);
    }

    static void H_dohanoi(int n, int t, int f, int u)
    {
    if (n > 0) {
    H_dohanoi(n-1, u, f, t);
    H_moveit(f, t);
    H_dohanoi(n-1, t, u, f);
    }
    }

    static void H_moveit(int from, int to)
    {
    System.out.print("move ");
    System.out.print(from);
    System.out.print(" --> ");
    System.out.println(to);
    }
    }

  2. #2
    pao
    pao is offline Member
    Join Date
    Jun 2008
    Posts
    43
    Rep Power
    0

    Default

    When you call it either from the commandline or your ide you need to pass in an argument. You see when main is called it takes string array and you can pass some params to your application.

    I also see that the value passed into args should be able to be cast to an Integer value as well...

    Did you write this code yourself? If you did I dont see your problem because you print this error string:

    Java Code:
    public static void main(String args[]) {
            //HERE YOU ARE CHECKING THE SIZE OF  args[]
            //IF IT IS NOT 1 YOU PRINT YOUR ERROR
            if (args.length != 1) {
                System.err.println("error: a single integer argument needed");
                System.exit(1);
            }
         
        }

  3. #3
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    ok thank you i know now what happen in the programme i will try to do some thing to work in right way

Similar Threads

  1. small error
    By ayoood in forum New To Java
    Replies: 23
    Last Post: 05-27-2008, 01:18 PM
  2. small issues with a program
    By jimJohnson in forum New To Java
    Replies: 6
    Last Post: 04-25-2008, 09:28 AM
  3. Building small web application in java for practice.
    By Saurabh321 in forum New To Java
    Replies: 1
    Last Post: 02-01-2008, 04:38 PM
  4. Small scale Java Editor
    By Greenfrog99 in forum AWT / Swing
    Replies: 0
    Last Post: 01-27-2008, 09:46 PM
  5. Small tennis simulation in Java
    By diego in forum New To Java
    Replies: 1
    Last Post: 12-02-2007, 02:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •