23. Write a program in java to input 10 integer number in an array including both negative and positive integer. Restore only positive number in separate array. Arrange and print only positive integer in descending order?

import java.io.DataInputStream;
class Descending
{
                public static void main(String args[])
                {
                                DataInputStream in=new DataInputStream(System.in);
                                int n[],d[],i,j,k=0,t;
                                n=new int[10];
                                d=new int[10];
                                try
                                {
                                                System.out.println("Enter Ten Integer Number (Negative and Positive) : ");
                                                for(i=0;i<10;i++)
                                                                n[i]=Integer.parseInt(in.readLine());
                                                for(i=0;i<10;i++)
                                                                if(n[i]>=0)
                                                                {
                                                                                d[k]=n[i];
                                                                                k++;
                                                                }
                                                for(i=0;i<k-1;i++)
                                                                for(j=i+1;j<k;j++)
                                                                                if(d[i]<d[j])
                                                                                {
                                                                                                t=d[j];
                                                                                                d[j]=d[i];
                                                                                                d[i]=t;
                                                                                }
                                }
                                catch(Exception e) {}
                                System.out.println("Display Array In Descending Order");
                                for(i=0;i<k;i++)
                                                System.out.println(d[i]);
                }
}

JAVA 23.PNG

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: