Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main
- {
- public static void main(String []args)
- {
- Scanner sc=new Scanner(System.in);
- int n;
- System.out.println("Enter the size of the array");
- n=sc.nextInt();
- int arr[]=new int[n];
- System.out.println("Enter the array");
- for(int i=0;i<n;i++)
- {
- arr[i]=sc.nextInt();
- }
- for(int i=0;i<n;i++)
- {
- for(int j=i+1;j<n;j++)
- {
- //Checking and swap
- if(arr[i]<arr[j])
- {
- int temp=arr[i];
- arr[i]=arr[j];
- arr[j]=temp;
- }
- }
- }
- System.out.println("Second Largest element is "+arr[1]); //Display second largest element.
- System.out.println("Second Smallest element is "+arr[n-2]); //Display second smallest element.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement