Question

Write a JAVA program that has a method which accepts a string and prints it back...

Write a JAVA program that has a method which accepts a string and prints it back to the user with all vowels replaced with *'s (multiple asterisks not '*s') with a new line after the string. The method signature should look like this:

public static void replacePrint(String input)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public static void replacePrint(String input) {
    for (int i = 0; i < input.length(); i++) {  // go through all characters
        char ch = input.charAt(i);
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
                ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
            System.out.print("*");
        } else {
            System.out.print(ch);
        }
    }
    System.out.println();
}

public class VowelsReplace {

    public static void replacePrint(String input) {
        for (int i = 0; i < input.length(); i++) {  // go through all characters
            char ch = input.charAt(i);
            if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
                    ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
                System.out.print("*");
            } else {
                System.out.print(ch);
            }
        }
        System.out.println();
    }

    public static void main(String[] args) {
        replacePrint("Hello How are you?");
    }
}

Add a comment
Know the answer?
Add Answer to:
Write a JAVA program that has a method which accepts a string and prints it back...
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
  • Write a JAVA program that has 2 methods with the same name: printCaps(String input) prints the...

    Write a JAVA program that has 2 methods with the same name: printCaps(String input) prints the input in capital letters, printCaps(String input, int num) prints in capital letters the specified number of times on a new line: public static void printCaps(String input) public static void printCaps(String input, int num)

  • JAVA Write a method that accepts a String as an argument. The method should use recursion...

    JAVA Write a method that accepts a String as an argument. The method should use recursion to display each individual character in the String. Then, modify the method you just wrote so it displays the String backwards. The following code does not correctly display the String backwards. It merely moves the first character of the String to the end: public static void displayCharacter(String s)    {        if(s.length() == 0)            return;        else       ...

  • and then print their average. Write a C program that accepts a string of text from...

    and then print their average. Write a C program that accepts a string of text from the user and prints back the string without any of the vowels. For example, if the user entered "Hello, world", the program should print "Hll, wrld" Write a C program that accepts an integer in decimal from the user and prints the number of 1' bits in the integers binary representation. For example, if the user entered 14, the program should print 3 because...

  • WRITTEN IN JAVA Complete the method printIndices that accepts a String source and a character search,...

    WRITTEN IN JAVA Complete the method printIndices that accepts a String source and a character search, and prints the position of each occurrence of the search value in source. For example: Input: source = "String Programming in Java is fun", search = 'i' Console Output: 3 15 19 27 Template provided from question:    public static int printIndices(String source, char search)    {    }    public static void main(String[] args)    {        System.out.println("Expected printIndices() prints indices 3...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Write a static method called printWithSpaces that takes a String as its parameter and prints the...

    Write a static method called printWithSpaces that takes a String as its parameter and prints the characters of the string separated by spaces. For example: > Methods.printWithSpaces("method") m e t h o d You should have a single space after the last character. This method should not return a value. That is similar to this code for printing the string vertically public static void printVertical(String s) { for (int i = 0; i < s.length(); i++) { char c =...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • By using Java public static methods solve following problem Write a method called vowelCount that accepts...

    By using Java public static methods solve following problem Write a method called vowelCount that accepts a String as its only parameter, and returns an array int[5] containing the count of vowels a,e,i,o,u in that String, using ignoreCase. For example, vowelCount("") returns {0,0,0,0,0}, and for the callvowelCount("Bill Iverson") your method returns {0,1,2,1,0} because there is one 'e' and two 'i' vowels (ignore case) and one 'o' with zero counts for 'a' and 'u' vowels.

  • JAVA Overview Create a method public static void spongeBobify(String inputPath, String outputPath...

    JAVA Overview Create a method public static void spongeBobify(String inputPath, String outputPath, Mode mode) that will convert a file to Mocking Sponge Bob text in 3 different modes. EveryOther capitalize the first letter of the string capitalize every other letter (ignoring non-letter character like punctuation and spaces). non-letter characters don't count toward the every other count Example: mocking sponge bob! → MoCkInG sPoNgE bOb! Vowels capitalize every vowel (not including y) Random capitalize each letter with a probability of 35%....

  • In the first task, you will write a Java program that accepts a string of the...

    In the first task, you will write a Java program that accepts a string of the format specified next and calculate the answer based on the user input. The input string should be of the format dddxxdddxx*, where d represents a digit and x represents any character and asterisk at the end represents that the string can have any number of characters at the end. 1. Prompt the user to enter a string with the specific format (dddxxdddxx*) 2. Read...

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