import java.util.*;
public class Main
{
static int sl(int a[]){
for(int i=0;i<a.length-1;i++)
for(int j=0;j<a.length-i-1;j++)
if(a[j]<a[j+1])
a[j]=a[j]^a[j+1]^(a[j+1]=a[j]);
return a[1];
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("how much elements u want to insert?");
n=sc.nextInt();
int a[]=new int[n];
System.out.println("enter "+n+" numbers :");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println("second largest no. is "+sl(a));
}
}
public class Main
{
static int sl(int a[]){
for(int i=0;i<a.length-1;i++)
for(int j=0;j<a.length-i-1;j++)
if(a[j]<a[j+1])
a[j]=a[j]^a[j+1]^(a[j+1]=a[j]);
return a[1];
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("how much elements u want to insert?");
n=sc.nextInt();
int a[]=new int[n];
System.out.println("enter "+n+" numbers :");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
System.out.println("second largest no. is "+sl(a));
}
}
No comments:
Post a Comment