I am trying to write a very simple program to receive input from the user and print it out again on the screen. But I'm getting an error.
My code:-
import java.util.*;
class res_cmd {
public static void main(String args[]){
int first;
System.out.println("Enter a number");
first = Integer.parseInt(args[0]);
System.out.println("The result is"+first);
}
}
The error I'm getting:-
C:\Users\hp\Desktop>java res_cmd
Enter a number
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at res_cmd.main(res_cmd.java:7)
I am not sure why I'm getting this error. Scanner class and Buffer method are working but command line is not. Please help.