import javax.swing.JOptionPane;
public class ArraySort
{
	public static void main(String[]args)
	{
		final int ARRAY_LENGTH = 100;
		int position;

		int[] x = new int[ARRAY_LENGTH];

		fill(x);
		print(x);

		sort(x);
		print(x);


		/*String input = JOptionPane.showInputDialog("Enter Number to Find");
		int findNum = Integer.parseInt(input);

		position = searchBinary (x, findNum);
		System.out.print ("Binary Search:  ");
		if(position > 0)
		{
			System.out.println (findNum + " was found at element " + position);

		}
		else
		{
			System.out.println(findNum + " was not found");
		}*/

	System.out.println("\n\n\n");
	System.exit(0);
	}

	//------------------------------Fill array with random integers between 0 and 99
	public static void fill (int[] x)
	{
		for (int i = 0; i <  x.length; i++)
		{
			x[i] = (int)( Math.random() * 100);
		}
	}

	public static void sort(int [] x)
	{
		boolean doMore = true;
		while (doMore)
		{
			doMore = false;  			// assume this is last pass over array
			for (int i=0; i<x.length-1; i++)
			{
				if (x[i] > x[i+1])
				{
						   				// swap
				   int temp = x[i];
				   x[i] = x[i+1];
				   x[i+1] = temp;
				   doMore = true;  		// after an exchange, must look again
				}
			}
		}
	}

	public static void print(int [] x)
	{
		System.out.print("\n\n");
		for (int i = 0; i < x.length; i++)
		{
			System.out.print(x[i]+", ");
		}
	}

	public static int searchBinary(int [] x, int findNum)
	{
		int low=0;
		int hi=x.length;
		int mid=(int)(hi/2);

		while (low<=hi-1)
		{
			if (x[mid]==findNum)
			{
				return mid;
			}
			if (x[mid]<findNum)
			{
				mid=(int)((mid+hi+1)/2);
			}
			else
			{
				mid=(int)((low+mid)/2);
			}
		}
	 	//not found
		 return -1;
	}
}