Array Program SDA

public class Main
{
public static void main(String[] args)
{
int a[]={7,8,9,3,6,2,5}; //output=8632579
int ar[]=new int[7];
int f=6;
int p=0;
int z=0;
int m=0;
int k=0;
int j=0;
for(int i=0;i<7;i++)
{
m=a[i];
z++;k=0;
for(j=0;j<7;j++)
{
if(m<=a[j])
{
m=a[j];
k=j;
}
}
a[k]=0;
if(z%2!=0)
ar[f--]=m;
else
ar[p++]=m;

System.out.print(a[i]);

}
System.out.println();
for(int i=0;i<7;i++)
System.out.print(ar[i]);
}
}

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...