I can get my program to compile but when I try to run it I get this message:
java Max1 2 51 2
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 3
at Max1.main(Max1. java:11)
here is my program:
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?
java Max1 2 51 2
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 3
at Max1.main(Max1. java:11)
here is my program:
Code:
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?
Comment