Question

In: Computer Science

Write a java program that read a line of input as a sentence and display: ...

Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.

Solutions

Expert Solution

Here is the Java code for both the problems.

Sample output is added at the end.

Code:

import java.util.Scanner;

public class StringDisplay {


    /*method to check if a character is lowercase vowel*/
    public static boolean isLowerVowel(char ch){

        if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'){    /*if chartacter is a vowel*/

            return true;

        }
        else{

            return false;

        }
    }

    public static void main(String[] args){

        Scanner scanner=new Scanner(System.in);   /*creates a new Scanner object*/

        System.out.println("Enter a sentence: ");

        String inputString=scanner.nextLine();   /*takes input from user*/

        StringBuilder vowelsReplaced=new StringBuilder();  /*creates a new StringBuilder object*/

        System.out.println("Uppercase letters in sentence are: ");

        for(int i=0;i<inputString.length();i++){    /*runs through all characters in string*/

            if(Character.isUpperCase(inputString.charAt(i))){          /*checks if character is uppercase*/

                System.out.print(inputString.charAt(i)+" ");     /*prints character*/

            }
        }

        for(int i=0;i<inputString.length();i++){     /*runs through all characters in string*/

            if(isLowerVowel(inputString.charAt(i))){     /*checks if the character is lowercase vowel*/

                vowelsReplaced.append('*');     /*append * to vowelsReplaced*/

            }
            else{

                vowelsReplaced.append(inputString.charAt(i));    /*append the character to vowelsReplaced*/

            }
        }

        System.out.println("\nSentence with lowercase vowels replaced by strike symbol is:\n"+vowelsReplaced.toString());  /*print the StringBuilder vowelsReplaced by converting it into string*/
    }
}

Sample Output:


Related Solutions

Write a program that will read a line of text. Display all the letters that occure...
Write a program that will read a line of text. Display all the letters that occure in the text, one per line and in alphabetical order, along with the number of times each letter occurs in the text. Use an array of base type int of length 26, so that the element at index 0 contains the number of a’s, the element at index 1 contains the number of b’s, and so forth, Alloow both upperCase and lower Case. Define...
Write a program in java that uses methods to input data for calculation, calculate, and display...
Write a program in java that uses methods to input data for calculation, calculate, and display the results of the calculations. That is, there are at least three methods. The problem is to write a program that calculates the area of a rectangle. This action should be repeatable.
Part 1 Write a program that reads a line of input and display the characters between...
Part 1 Write a program that reads a line of input and display the characters between the first two '*' characters. If no two '*' occur, the program should display a message about not finding two * characters. For example, if the user enters: 1abc*D2Efg_#!*345Higkl*mn+op*qr the program should display the following: D2Efg_#! 1) Name your program stars.c. 2) Assume input is no more than 1000 characters. 3) String library functions are NOT allowed in this program. 4) To read a...
Write a java program that will take a line of input and go through and print...
Write a java program that will take a line of input and go through and print out that line again with all the word numbers swapped with their corresponding numeric representations (only deal with numbers from one to nine). Sample runs might look like this: Please enter a line of input to process: My four Grandparents had five grandchildren My 4 grandparents had 5 grandchildren without array and methods.
Write a JAVA program read a number within the range of 1 through 1000 to display...
Write a JAVA program read a number within the range of 1 through 1000 to display the Roman numeral version of that number. Include screenshot of the output
Write a program that will read in from input file one line at a time until...
Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces, commas and periods....
Display the shortest words in a sentence in JAVA Write a method that displays all the...
Display the shortest words in a sentence in JAVA Write a method that displays all the shortest words in a given sentence. You are not allowed to use array In the main method, ask the user to enter a sentence and call the method above to display all the shortest words in a given sentence. You must design the algorithms for both the programmer-defined method and the main method.
JAVA Assignment: Project File Processing. Write a program that will read in from input file one...
JAVA Assignment: Project File Processing. Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of...
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT