PROGRAM FOR ARRANGING THE STRINGS IN SORTING ORDER

import java.io.*; class Ordering { static String name[] =    {"Madras","delhi","Ahmadabad","Calcu...

import java.io.*;
class Ordering
{
static String name[] =    {"Madras","delhi","Ahmadabad","Calcutta","Bombay"};
            public static void main(String args[])
            {
                        int size=name.length;
                        String temp=null;
                        for(int i=0; i < size; i ++ )
                        {
                           for(int j=i+1; j < size; j ++ )
                           {
                                    if(name[j].compareTo(name[i] ) < 0 )
                                    {
                                                temp=name[i];
                                                name[i]=name[j];
                                                name[j]=temp;
                                    }
                           }
                        }
                        for(int i=0; i < size ; i ++ )
                        {
                                    System.out.println(name[i]);
                        }
            }
}

  

OUTPUT:

Ahmadabad
Bombay
Calcutta
Madras

delhi

Related

Explain about Thread priority in Java?

 In Java, each thread is assigned as priority which affects the order in which it is schedule for running.  The Threads of the same priority are given equal treatment by the Java sch...

Explain Thread exceptions?

Sleep method is enclosed in a try blocked followed by a catch block. This is necessary because the sleep( ) throws an exception, which should be caught .if we fail to ...

Write about Entry controlled loop and Exit controlled loop?

Loop means, A sequence of statements are executed until some conditions for termination of the loop are satisfied. A program loop consists of 2 segments 1. Body of the loop & 2. C...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item