Find Largest Number

public static void main(String[] args)

{

int n1=10, n2=20;

if(n1>n2)
{
System.out.println(“Maximum value:”+n1);
}
else
{
System.out.println(“Maximum value:”n2);

}
}

———————————————————

public static void main(String[] args)

{

int n, max;

Scanner s = new Scanner(System.in);

System.out.print(“Enter number of elements in the array:”);

n = s.nextInt();

int a[] = new int[n];

System.out.println(“Enter elements of array:”);

for(int i = 0; i < n; i++)

{

a[i] = s.nextInt();

}

max = a[0];

for(int i = 0; i < n; i++)

{

if(max < a[i])

{

max = a[i];

}

}

System.out.println(“Maximum value:”+max);

}