Monday, 1 August 2011

Simple program to arrange the citynames in ascending order


Simple program to arrange the citynames in ascending order

class stasc
{
                    public static void main (String args [ ])
                    {
                                        int I, j;
                                        String st;
                                        for (i=0 ; I <args.length ; i++ )
                                        {
                                                            for(j=0 ; j < args.length-1; j ++)
                                                            {
                                                            if (args [ j].compareTo( args {j + 1] )>0)
                                                            {
                                                            st=args[ j ] ;
                                                            args [ j] =args [ j + 1]
                                                            args [ j + 1 ];
                                                            args [ j + 1 ] =st ;
                                                            }
                                                            }
                                        }
                    for(i=0; i< args.length; i++)
                    {
                                        System.out.println(args [ i] );
                    }
}
}
Output :
                    Java stasc xyz abc hello
                    abc
                    hello
                    xyz

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More