1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | class sorting { public static void main(String[] input) { int k=input.length; String temp=new String(); String names[]=new String[k+1]; for(int i=0;i<k;i++) { names[i]=input[i]; } for(int i=0;i<k;i++) for(int j=i+1;j<k;j++) { if(names[i].compareTo(names[j])<0) { temp=names[i]; names[i]=names[j]; names[j]=temp; } } System.out.println(“Sorted order is”); for(int i=0;i<k;i++) { System.out.println(names[i]); } } } |
Output:
Java sorting Harish Ramesh Mahesh Rakesh
Sorted order is
Ramesh
Rakesh
Mahesh
Harish
Java sorting sai hari teja ravi sandeep
Sorted order is
teja
sandeep
sai
ravi
hari
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
May 5th, 2011 at 8:50 pm
Hey, i am meek and i am thankful to you for this code of sorting learning sorting in Java language .
October 13th, 2011 at 2:18 am
no m funciono man!!!! ufff q mal!!!!