THE LARGEST VALUE IN AN ARRAY
PROGRAM TO FIND LARGEST VALUE IN ARRAY
import java.util.Scanner; //Import the Scanner class
class Largest_value
{
public static void main(String args[])
{
int num[] = new int[60];
int i, L=0, size;
System.out.print("Enter array size: ");
Scanner in = new Scanner(System.in);
size=in.nextInt();
//Insert value in size variable at run time
//size=in.nextInt();
System.out.println("Enter values in array:");
//Scanner in = new Scanner(System.in);
for(i=0; i<size; i++)
{
num[i]=in.nextInt();
}
//Loop to find the largest value.
for(i=0; i<size; i++)
{
if(L < num[i])
L = num[i];
}
System.out.println("Largest value is: "+L);
}
}
- - - PROGRAM OUTPUT - - -
0 Comments