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

Question #323343

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 (Use a Search function to locate the value with in the array) and replace that value with the character @.

 

 * *Print out arrayAlphabetizer with the replaced element..


1
Expert's answer
2022-04-04T16:11:55-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 str){
        str = str.replaceAll(" ", "");
        System.out.println(str);
        return str.length();
    }


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

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

        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