Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

second largest number in array

public static void SecondndLargestfromarray()
{
    var scan = new Scanner(System.in);
    var n = scan.nextInt();
    long l=Long.MIN_VALUE;
    long p=Long.MIN_VALUE;

    for (int i = 0; i < n; i++) {
        var sc = scan.nextLong();
        if(sc>l)
        {
            p=l;
            l=sc;
        }
        else if(sc>p ) p = sc;
    }
    System.out.println(p);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #largest #number #array
ADD COMMENT
Topic
Name
2+6 =