java Max1 2 51 2
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at Max1.main(Max1.java:11)
here is my program:
Expand|Select|Wrap|Line Numbers
- public static void main(String[] args){
- int max = Integer.MIN_VALUE;
- int var = Integer.parseInt(args[args.length]);
- int x[] = new int[var];
- for (int i = 0; i < args.length; i++) {
- if(x[i] > max)
- max = x[i];
- System.out.print(max);
I know that it means im trying to reach an index that is unavailable but I just dont know how to make it work so that a user types in however many numbers he wants, and the program outputs the largest number value.
I know this is probably really simple, but help?