Created
January 23, 2021 05:04
-
-
Save laxmankumar2000/8ec29b5b022e126c230a72728b64b318 to your computer and use it in GitHub Desktop.
ArrayIndexOutOfBoundsexception
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Array_Pragrom; | |
import java.util.Scanner; | |
public class SecLargest { | |
public static int geLargest(int arr[] , int num) | |
{ | |
int temp = 0; | |
for(int i =0; i<arr.length ; i++) | |
{ | |
for (int j = i+1; j < arr.length ; j++) { | |
if(arr[i]>arr[j]) { | |
temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
} | |
} | |
} | |
return arr[num-2]; | |
} | |
public static void main(String[] args) { | |
int num =0; | |
int[] arr = new int[num]; | |
Scanner obj = new Scanner(System.in); | |
num = obj.nextInt(); | |
for (int i = 0; i <= num; i++) { | |
arr[i] = obj.nextInt(); | |
} | |
System.out.println(geLargest(arr,num)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment