Click the Twitter icon to follow our tweets and
know more about us.

WAP to fill an array with negative and positive numbers in any order and place and then shift the negative numbers to left side and positive numbers to right side without changing their order

import java.io.*;
class neg
{
     public static void main()throws IOException
     {
         DataInputStream k=new DataInputStream(System.in);
         System.out.println("Fill The Array");
         int a[]=new int[10];
         for(int i=0;i<10;i++)
         a[i]=Integer.parseInt(k.readLine());
         int b=0;
         for(int i=0;i<10;i++)
         {
             if(a[i]<0)
             {
                 int t=a[i];
                 for(int j=i;j>b;j--)
                 a[j]=a[j-1];
                 a[b]=t;
                 b++;
             }
         }
         System.out.println("After Arranging");
         for(int i=0;i<10;i++)
         System.out.println(a[i]);
        }
    }

Comments (0)

Post a Comment