mercredi 26 février 2020

How to print out a random character of a string?

I have an assignment due for my java course and I cant figure out how to print out a random character from a string the user has input, can anyone lend a hand? don't mind the if(section == 2), thats the users choice of what to do to the string and choice 2 is to print out a random char

Currently I have some code that looks like this

        Scanner keyboard = new Scanner(System.in);          

        String input = keyboard.next();

        Random random = new Random();
        char index = random.charAt(input.length());


        if(selection == 2)
          System.out.println("Here is a random Character ");
          System.out.println(index);



Aucun commentaire:

Enregistrer un commentaire