Results 1 to 3 of 3
Thread: Small problem
- 06-06-2008, 12:14 PM #1
Member
- Join Date
- May 2008
- Posts
- 39
- Rep Power
- 0
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);
}
}
- 06-06-2008, 12:22 PM #2
Member
- Join Date
- Jun 2008
- Posts
- 43
- Rep Power
- 0
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); } }
- 06-06-2008, 12:27 PM #3
Member
- Join Date
- May 2008
- Posts
- 39
- Rep Power
- 0
Similar Threads
-
small error
By ayoood in forum New To JavaReplies: 23Last Post: 05-27-2008, 12:18 PM -
small issues with a program
By jimJohnson in forum New To JavaReplies: 6Last Post: 04-25-2008, 08:28 AM -
Building small web application in java for practice.
By Saurabh321 in forum New To JavaReplies: 1Last Post: 02-01-2008, 03:38 PM -
Small scale Java Editor
By Greenfrog99 in forum AWT / SwingReplies: 0Last Post: 01-27-2008, 08:46 PM -
Small tennis simulation in Java
By diego in forum New To JavaReplies: 1Last Post: 12-02-2007, 01:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks