I also want to compare the max number but I am having problems with inserting it in an array - it gives the error:
java.lang.ArrayIndexOutOfBoundsException
Whenever I insert a value larger than 5.
import java.util.Scanner;
public class LargestValue
{
public static void main(String[] args)
{
Scanner sc= new Scanner (System.in);
int a[] = new int[5];
System.out.println ("Enter 5 numbers for comparison ");
for (int j = 0; j < a.length; j++)
{
int inputNumber = sc.nextInt();
a[inputNumber] = inputNumber;
System.out.println(inputNumber);
}
}
}
a[j] = inputNumber;instead ofa[inputNumber] = inputNumber;