Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 sortstring.java
Index -> Programming, Java -> Java Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
alpesh




PostPosted: Mon Jan 26, 2004 12:56 am   Post subject: sortstring.java

/*

WAP To accept more than one string and arrange them in alphabetical order

--------------
public int compareTo(String anotherString)

Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings.

Parameters:
anotherString - the String to be compared.
Returns:
the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument.


*/

import java.io.*;
public class sortstring
{
public static void main(String arg[])
{
int n;
String name[],nS;
n=0;
name = new String[20];
try
{
DataInputStream in;
in = new DataInputStream(System.in);
System.out.println("Enter no of Entry : ");
System.out.flush();
nS = in.readLine();
n = Integer.parseInt(nS);
System.out.println("Enter " + n + " entries ");
System.out.flush();
for(int i=0;i<n;i++)
{
System.out.flush();
name[i] = in.readLine();
}
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
String t;
if(name[i].compareTo(name[j])>0)
{
t = name[i];
name[i]=name[j];
name[j]=t;
}
}
}
catch(IOException e)
{
System.out.println("In out error");
System.exit(1);
}
System.out.println("Alphabatical order ");
for(int i=0;i<n;i++)
{
System.out.println(name[i]);
}
}
}
Sponsor
Sponsor
Sponsor
sponsor
shorthair




PostPosted: Thu Jan 29, 2004 9:36 am   Post subject: (No subject)

Great Acomplishment , well done , im quite interested in getting to know java , looks like you can harness alot of power with java
Display posts from previous:   
   Index -> Programming, Java -> Java Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: