Answer to Question #324666 in Java | JSP | JSF for reaper

Question #324666

Create a program using a Java console application name it "Alphabetizer". The program should ask the user to enter is name and surname.

Create a method called emptySpace () this remove space between the name and the surname (Use a regular expression "replaceAll"). The emptySpace() method also Count the number of characters within the newly created string (nameSurname) and return the total number of Characters .

The total number of characters (Name and Surname) should be the size of your arrayAlphabetizer (type integer). Populate your arrayAlphabetizer with a series of random numbers between 10 and 50.

Display all arrayAlphabetizer elements and they are corresponding indexes before executing the sort() method and after executing the sort(). Allow the user to enter a value from the arrayAlphabetizer element to search for.

Loop through the array until you find the value and replace that value with the character @.

 Print out arrayAlphabetizer with the replaced element..


1
Expert's answer
2022-04-06T05:07:45-0400
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Main {

    public static int emptySpace(String nameSurname){
        nameSurname = nameSurname.replaceAll(" ", "");
        return nameSurname.length();
    }


    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        String nameSurname= in.nextLine();
        Random rand = new Random();

        String[] arrayAlphabetizer = new String[emptySpace(nameSurname)];

        for (int i = 0; i < arrayAlphabetizer.length; i++) {
            arrayAlphabetizer[i] = "" + rand.nextInt(10, 51);
        }

        System.out.println(Arrays.toString(arrayAlphabetizer));

        String ch = in.next();

        for (int i = 0; i < arrayAlphabetizer.length; i++) {
            if(ch.equals(arrayAlphabetizer[i])){
                arrayAlphabetizer[i] = "@";
            }
        }

        System.out.println(Arrays.toString(arrayAlphabetizer));


    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS