Java Eclipse error java.lang.ArrayIndexOutOfBoundsException
Hi frndz my code is
public class ADD
{
public static void main(String[] args)
{
int a,b;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
System.out.println("sum is "+(a+b));
}
}
when I used it from cmd it works fine
output:-
c:\>java ADD 5 9
sum is 14
I am new on Java Eclipse but same code when I used in Java Eclipse IDE it gives me Error:-
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at ADD.main(ADD.java:7)
Plz Help Thnx....
Re: Java Eclipse error java.lang.ArrayIndexOutOfBoundsException
Did you pass your command line arguments? My guess is that you didn't ... it isn't Eclipse's fault.
kind regards,
Jos
Re: Java Eclipse error java.lang.ArrayIndexOutOfBoundsException
hey I got it....
I found Arguments tab in Run config...
THNX...
Re: Java Eclipse error java.lang.ArrayIndexOutOfBoundsException
Dis s d correct one..try this..
public static void main(String[] args) throws IOException {
System.out.println("Addition of two numbers!");
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String s=buf.readLine();
int a=Integer.parseInt(s);
String t=buf.readLine();
int b=Integer.parseInt(t);
int sum = a + b;
System.out.println("Sum: " + sum);
}
}
Re: Java Eclipse error java.lang.ArrayIndexOutOfBoundsException
how u got ..could u pls explain ???
Re: Java Eclipse error java.lang.ArrayIndexOutOfBoundsException
Forum Rules
http://www.java-forums.org/forum-gui...w-members.html
BB Code List - Java Programming Forum
Also, don't spoonfeed code and don't post to long dead threads. The question was asked more than a year ago.
db
THREAD CLOSED