|
-
this is my source
i need this program to sort an array of strings alphabetically, I.e. if array[0] is zak, and array[1] is bob, then the arrays should switch order....
/*
import java.io.*;
public class ArrayLab
{
public static void main(String[] asdf) throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("How many names? : ");
int arraysize=Integer.parseInt(input.readLine());
String [] names = new String [arraysize];
for(int z=0;z<arraysize;z++)
{
System.out.print("Please enter a name: ");
names[z] = input.readLine();
}
//int min;
//String temp=names[0];
//
//for(int index=0; index<arraysize-1;index++)
// {
// min=index;
// for(int scan= index+1; scan< arraysize; scan++)
// if(names[scan].compareTo(names[index]) < 0)
// min=scan;
//
//
// temp=names[min];
// names[min]= names[index];
// names[index]=temp;
// }
int min;
String temp=names[0];
for(int index=0; index<arraysize-1;index++)
{
// min=index;
for(index=0;index<arraysize-1-index;index++)
{
if(names[index+1].compareTo(names[index]) < 0)
{
//min=scan;
temp=names[index];
names[index]=names[index+1];
names[index+1]=temp;
}
}
}
//prints the arrays
for(int i=0;i<arraysize;i++)
{
System.out.println((i+1) + ") " + names[i]);
}
System.out.println("");
System.out.println("");
System.out.println(" Would you like to change a name? (1 for yes , 2 for No)");
int choice= Integer.parseInt(input.readLine());
for(int z=0; z<1
{
if(choice==2)
z=1;
else if(choice==1)
{
System.out.println(" Which name would you like to change? (0 -" + arraysize + " )");
int arraychoice= Integer.parseInt(input.readLine());
System.out.println( " Enter changes : ");
String arraychange=input.readLine();
names[arraychoice]=arraychange;
System.out.println("");
System.out.println("");
for(int i=0;i<arraysize;i++)
{
System.out.println(i + ") " + names[i]);
}
System.out.println("Any more changes? (1 for Yes, 2 For No)");
int more= Integer.parseInt(input.readLine());
if(more==1)
z=0;
else
z=1;
}
}
}
}
*/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks