Help with my code to find MinOfAll numbers
I am new to Programming world and so to Java,
I tried my hands on writing the following code to find minimum of all the numbers entered via command prompt,
but I am getting the error
Exception in thread "main" java.lang.ArrayIndexOutOfBound Exception :5 at MinOfAll.main
Kindly tell me where am I going wrong?
Code:
public class MinOfAll{
public static void main(String[] args){
int result = Integer.parseInt(args[0]);
for (int i =0 ; i< args.length; i++)
{
int current=Integer.parseInt(args[i+1]);
if (current < result){
result = current;
}
}
System.out.println("Min of all is : " + result);
}
}
[color=red]I/P at console : java MinOfAll 2 3 4 5 6[/color]
Thanks Erangs, its working
My bad I had kept the same code at 2 places ad was running the unpdated one.
Thanks again!!