22. Write a program in java to input some integer number using keyboard arrange and print all input number in array in ascending order?

import java.io.DataInputStream;
class Ascending
{
                public static void main(String args[])
                {
                                DataInputStream in=new DataInputStream(System.in);
                                int n[],x=0,i,j,t;
                                n=new int[100];
                                try
                                {
                                                System.out.println("Enter Size of Array : ");
                                                x=Integer.parseInt(in.readLine());
                                                for(i=0;i<x;i++)
                                                                n[i]=Integer.parseInt(in.readLine());
                                                for(i=0;i<x-1;i++)
                                                                for(j=i+1;j<x;j++)
                                                                                if(n[i]>n[j])
                                                                                {
                                                                                                t=n[j];
                                                                                                n[j]=n[i];
                                                                                                n[i]=t;
                                                                                }
                                }
                                catch(Exception e) {}
                                System.out.println("Display Array In Ascending Order");
                                for(i=0;i<x;i++)
                                                System.out.println(n[i]);
                }
}

JAVA 22.PNG

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: