U2p9.java

import java.util.*; public class u2p9 { public static void main(String ar[]) { Scanner sc= new Scanner(System.in); System.out.println("Enter how many Word u want to enter"); int size=sc.nextInt(); String word[]=new String[size]; String temp; int i; for(i=0;i<size;i++) { word[i]=sc.next(); } for(i=0;i<size;i++) { for(int j=i+1;j<size;j++) { if(word[i].compareTo(word[j])>0) { temp=word[i]; word[i]=word[j]; word[j]=temp; } } } System.out.println("Sorted Word list"); for(i=0;i<size;i++) { System.out.println(word[i]); } } } /*in this program i have used the String method "compareTo(String anotherString)" this method Compare two Strings.*/

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.