import java.util.Arrays;
public class secondlargest {
public static void main(String[] args) {
int a[] = { 0,80,200,500,900};
Arrays.sort(a);
for(int i=0;i<a.length;i++)
{
System.out.println("after sorting "+a[i]);
}
int largest = a[0];
int secondlargest = a[0];
int cmp = 0;
for (int i = 0; i < a.length; i++) {
if (largest < a[i]) {
secondlargest = largest;
largest = a[i];
}
else if(a[i]>secondlargest)
{
secondlargest = a[i];
}
}
System.out.println("sec lar is "+secondlargest);
System.out.println("lar is " + largest);
}
}
public class secondlargest {
public static void main(String[] args) {
int a[] = { 0,80,200,500,900};
Arrays.sort(a);
for(int i=0;i<a.length;i++)
{
System.out.println("after sorting "+a[i]);
}
int largest = a[0];
int secondlargest = a[0];
int cmp = 0;
for (int i = 0; i < a.length; i++) {
if (largest < a[i]) {
secondlargest = largest;
largest = a[i];
}
else if(a[i]>secondlargest)
{
secondlargest = a[i];
}
}
System.out.println("sec lar is "+secondlargest);
System.out.println("lar is " + largest);
}
}
No comments:
Post a Comment