public class bubble { /* main function */
public static void main(String[] args)
{
int random, flag, temp;
int numarray[] = new int[100]; /* declares a new integer array holding from 0 to 99 */
char letarray[] = new char[100]; /* declares a new character array holding 0 to 99 */
char tamp;
System.out.print("\n\nUnsorted Array\n"); /* for loop goes here for printing out the array of chars */
for(int i = 0; i < 100; i++)
{
random = (int)(Math.random()*90) + 1;
if (random != 0 && random >= 65)
{
numarray[i] = random;
letarray[i] = (char)random;
System.out.print("\t" + letarray[i] + " ");
}
}
do { /* do...while loop to sort the array */
flag=0;
for(int j=0; j<99; j++)
{
if(numarray[j] > numarray[j+1])
{
temp = numarray[j];
tamp = letarray[j];
numarray[j] = numarray[j+1];
numarray[j+1] = temp;
letarray[j] = letarray[j+1];
letarray[j+1] = tamp;
flag = 1;
}
}
} while(flag!=0); /* end of bubble sort */
System.out.print("\nSorted Array"); for(int k=0; k<100; k++) /* print sorted array */
{
System.out.print("\t" + letarray[k] + " ");
}
}
}