Question

Write a java program that generates 10 random lowercase letters (range from ‘a’ – ‘z’) and...

Write a java program that generates 10 random lowercase letters (range from ‘a’ – ‘z’) and stores the characters in an array. Call a method that replaces all repetitions of a character with asterisk character ‘*’. Use JOptionPane to show the content of the array in main method.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javax.swing.*;

public class RandomCharacters {

    public static void removeRepetitions(char[] letters) {
        for (int i = 0; i < letters.length; i++) {
            for (int j = 0; j < i; j++) {
                if (letters[i] == letters[j]) {
                    letters[i] = '*';
                }
            }
        }
    }

    public static void main(String[] args) {
        char[] letters = new char[10];
        for (int i = 0; i < letters.length; i++) {
            letters[i] = (char) ('a' + Math.random() * 26);
        }
        removeRepetitions(letters);
        String s = "";
        for (int i = 0; i < letters.length; i++) {
            s += letters[i] + " ";
        }
        JOptionPane.showMessageDialog(null, s);
    }
}

Message (1) Iknaq* c* ey OK

Add a comment
Know the answer?
Add Answer to:
Write a java program that generates 10 random lowercase letters (range from ‘a’ – ‘z’) and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The code below generates 10 random lowercase characters a – z and stores the characters in...

    The code below generates 10 random lowercase characters a – z and stores the characters in memory. Expand this code to CAPITALIZE all the characters in memory. Your code should iterate all characters in memory and change their value to their uppercase equivalent. For instance, character ‘a’ would become ‘A and ‘z’ would become ‘Z’.    Hint: The ASCII table on the backside of this sheet will be necessary in answering this question. li $t0, 0 # i= 0 move $s0,...

  • Java Programming - Write a program that generates two random integers, both in the range 25...

    Java Programming - Write a program that generates two random integers, both in the range 25 to 75, inclusive. Use the Math class. Print both integers and then display the positive difference between the two integers, but use a selection. Do not use the absolute value method of the Math class.

  • Write a function that converts all the lowercase letters in an array of 10 characters to...

    Write a function that converts all the lowercase letters in an array of 10 characters to uppercase. This should be done by directly manipulating the ASCII values of the characters. The user should be prompted to enter the characters.

  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • Write a program that deletes an element of a one-dimensional array of characters. The program should:...

    Write a program that deletes an element of a one-dimensional array of characters. The program should: Ask user to input the number of characters in the array the values of the array a character to be deleted Call a method to delete the character Print the resulting array or, if the character is not found, print “Value not found” The method called by the main program should: Pass the array and the character to be found as parameters If the...

  • C Programming. Write a prograrm that generates a "random walk" across a 10 × 10 array....

    C Programming. Write a prograrm that generates a "random walk" across a 10 × 10 array. The array will con- tain characters (all ' . ' initially). The program must randomly "walk" from element to ele- ment, always going up, down, left, or right by one element. The elements visited by the program will be labeled with the letters A through Z, in the order visited. Here's an example of the desired output: 9. BCD.. F E. H G KR...

  • Write a program that generates an array filled up with random positive integer number ranging from...

    Write a program that generates an array filled up with random positive integer number ranging from 60 to 100, and display it on the screen. After the creation and displaying of the array, the program displays the following: [R]everse [A]dd [S]earch E[xit] Please select an option:_ Then, if the user selects: - R (lowercase or uppercase): the program displays the reversed version of the array. - A (lowercase or uppercase): the program displays the sum of the elements of the...

  • In C++ write a complete and correct x++ program that generates student email addresses and prints...

    In C++ write a complete and correct x++ program that generates student email addresses and prints them to the screen based upon the data found in an input file, called students . txt. Each line of the space, followed by the student’s last name. Every email address is to be of the form [email protected]. In general, each username has four parts in this order: (i) the student; last name in lowercase letters; (ii) a number between 10- 99 generated at...

  • Write a C++ program that generates an array filled up with random positive integer number ranging...

    Write a C++ program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit Please select an option: Then, if the user selects: -P (lowercase or uppercase): the program displays the array elements position and value pairs for all member elements of the array. -R (lowercase or uppercase): the...

  • Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that...

    Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that holds an array for the integer values 1-10. Pass the array to a method that will calculate the values to the power of 2 of each element in the array. Then return the list of calculated values back to the main method and print the values

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT