Consider the below Array
{4,5,3,8,9,1,6,7,12,5,9,32,1}
Using only single loop find out the second largest number form given array.
Output sholud be : 12.
788 B
1 KB
It works fine but seems much complex.
I have changed code of MyClass.java file for this logic.
public class SecondhighestSum { public static void main(String args[]) { int[] intArray = {24, 5, 3, 8, 9, 1, 6, 3, 12, 5, 9, 8, 12}; int intHighestnumber = 0; int intSecondhighestnumber = 0; for (int intnumber = 0; intnumber < intArray.length - 1; intnumber++) { int num = intArray[intnumber] + intArray[intnumber + 1]; if (intHighestnumber < num) { intSecondhighestnumber = intHighestnumber; intHighestnumber = num; } else { if (intSecondhighestnumber < num && num != intHighestnumber) { intSecondhighestnumber = num; } } } System.out.println("SecondHighest Number " + intSecondhighestnumber); } }
Please test above code.
-Amol
It works fine but seems much complex.
I have changed code of MyClass.java file for this logic.
public class SecondhighestSum { public static void main(String args[]) { int[] intArray = {24, 5, 3, 8, 9, 1, 6, 3, 12, 5, 9, 8, 12}; int intHighestnumber = 0; int intSecondhighestnumber = 0; for (int intnumber = 0; intnumber < intArray.length - 1; intnumber++) { int num = intArray[intnumber] + intArray[intnumber + 1]; if (intHighestnumber < num) { intSecondhighestnumber = intHighestnumber; intHighestnumber = num; } else { if (intSecondhighestnumber < num && num != intHighestnumber) { intSecondhighestnumber = num; } } } System.out.println("SecondHighest Number " + intSecondhighestnumber); } }
Please test above code.
-Amol
Scenario 2:
Find out the second largest sum(sum of adjacent number) of unsorted array using single loop.
Consider below example:
{5,3,4,2,1,6,8,7,1,2,6,4}
Array after sum of adjacent number is {8,7,6,3,7,14,15,8,3,8,10}
Second largest pair sum is 14.
Scenario 2:
Find out the second largest sum(sum of adjacent number) of unsorted array using single loop.
Consider below example:
{5,3,4,2,1,6,8,7,1,2,6,4}
Array after sum of adjacent number is {8,7,6,3,7,14,15,8,3,8,10}
Second largest pair sum is 14.
Scenario 3:
Find out the pair of original numbers of second largest number of this program.
Consider the second largest is 14, print the pair of 14 is { 8 , 6 }
Scenario 3:
Find out the pair of original numbers of second largest number of this program.
Consider the second largest is 14, print the pair of 14 is { 8 , 6 }
Please Test the same and let me know
-Master Oogway.
Please Test the same and let me know
-Master Oogway.
Field | Old Value | New Value |
---|---|---|
Resolution | Fixed | |
Resolved Date | Dec 1, 2017 4:22 PM | |
Status | New | Resolved |
Issue #1 |
Resolved |
Fixed |
Resolved |
Completion |
No due date |
No fixed build |
No time estimate |