Loading
notes intro/old submit AP Problems the dump links
 

String Sort

 

Create a class StringSort with code below. Write the method that will print out the names in alpha order. Extra Credit to anyone who does it w/ 3 if statements.

Challenge:

Make a new method printInAlpha that will take a name and print its characters in alphabetical order

public class StringSort
{
	String name1;
	String name2;
	String name3;
	public StringSort()
	{
		String[] names={"Mica", "David", "Ian","T.J.", "Julia","Peter Pan", "Herbert", "Mondale", "Slimeboy", "T-Rex"};
	    name1=names[(int)(Math.random()*10)];
	    name2=names[(int)(Math.random()*10)];	    
	    name3=names[(int)(Math.random()*10)];	    
	}

	public void printAlpha()
	{
	    System.out.println(name1);
	    System.out.println(name2);
	    System.out.println(name3);	    
	}

	public static void main(String args[])
	{
		StringSort s = new StringSort();
		s.printAlpha();
	}
}