
class Maxof2{
public static void main(String args[]){
//taking value as command line argument.
//Converting String format to Integer value
int i = Integer.parseInt(args[0]);
int j = Integer.parseInt(args[1]);
if(i > j)
System.out.println(i+" is greater than "+j);
else
System.out.println(j+" is greater than "+i);
}
}

Hi Friend,
ArrayIndexOutOfBoundsException:0 means that you haven't specify the arguments along with run command.
Run your code with the following statement:
java Maxof2 5 6
When you will execute your code with the above statement then you will get the output, otherwise you will get the ArrayIndexOutOfBoundsException.
We have specified 5 and 6 as arguments. You can take any number but you have to specify only two numbers.
If you want another way of finding the greatest among two numbers then you can try the following code also.
import java.util.*;
class Maxof2{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
System.out.print("Enter Number 1: ");
int i = input.nextInt();
System.out.print("Enter Number 2: ");
int j = input.nextInt();
if(i > j)
System.out.println(i+" is greater than "+j);
else
System.out.println(j+" is greater than "+i);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.