This code is written in notepad and run in the command prompt.
The input is computer is fun
, and the output is:
fun
is
computer
When I tried to write it in NetBeans, it gives me an error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
What is the problem, and how can I get the same output as when I run it in the command prompt?
class A{
public static void main(String[] args) {
args[0]="Computer";
args[1]="Science";
args[2]="is";
args[3]="fun";
if (args.length>1)
{
String []newargs = new String [args.length-1];
for (int i = 0 ; i<newargs.length ;i++)
{
newargs[i]=args[i+1];
}
main (newargs);
//System.out.println(args.length);
}
System.out.println(args[0]);
return;
}
}