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 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.
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...
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 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.
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Design and implement a C++ program read in a whole line of characters as the input...
Design and implement a C++ program read in a whole line of characters as the input string; count and display how many times how frequently (among the letters) each (case insensitive) letter appears in the above mentioned input string; Sample program execution: An example of executing such a program is shown below. Note that the user input is in italic font. Please enter a line of characters: This is a really long line of characters! There are 41 characters in...
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT