Finding Second Largest number in a given Array

 

import java.util.*;

public class SecondLargestNo {
public static int findNo(int arr[]) {
int firstLargest = 0;
int secondLargest = 0;
if (arr[0] > arr[1]) {
firstLargest = arr[0];
secondLargest = arr[1];
} else {
firstLargest = arr[1];
secondLargest = arr[0];
}
for (int i = 2; i < arr.length; i++) {
if (arr[i] > firstLargest) {
secondLargest = firstLargest;
firstLargest = arr[i];
} else if (arr[i] < firstLargest && arr[i] > secondLargest) {
secondLargest = arr[i];
}
}
return secondLargest;
}

public static void main(String args[]) {
System.out.println("Second Largest no in the given array is :");
System.out.println(findNo(new int[] { 985, 521, 975, 831, 479, 861 }));
System.out.println(findNo(new int[] { 185, 121, 432, 131, 430, 465 }));
System.out.println(findNo(new int[] { 47498, 14526, 74562, 42681, 75283, 45796 }));
System.out.println(findNo(new int[] { 9459, 9575, 5692, 1305, 1942, 9012 }));
}
}

Google Script for Data Entry Form in Google Spreadsheet

// function to validate the entry made by user in user form function validateEntry (){ // declare a variable and referernece of active goog...