lundi 16 novembre 2015

How do I sort randomly generated characters alphabetically?

this is what I have so far

public class RandomCharacter
{
    public static char getRandomUpperCaseLetter()
    {
        int ascii = (int) (Math.random()*26) + (int) 'A';
        return (char)ascii;
    }
    public static char getRandomDigitCharacter()
    {
        int digit = (int)(Math.random()*10) + (int) '0';
        return (char)digit;
    }

    public static void main(String [] args)
    {

        for (int i = 1; i <= 100; i++)
        {
            System.out.print(getRandomUpperCaseLetter());
            if(i%10 == 0) 
                System.out.print("\n"); 
        }

    }
}

I have no clue how to specifically order this alphabetically, I have tried for hours but could not find anything for this.




Aucun commentaire:

Enregistrer un commentaire