Question

In: Computer Science

Write a class to accept a sentence from the user and prints a new word in...

Write a class to accept a sentence from the user and prints a new word in a terminal formed out of the third letter of each word. For example, the input line “Mangoes are delivered after midnight” would produce “neltd”.

Program Style : Basic Java Programming

Solutions

Expert Solution

CODE:

import java.util.*;
class Solution 
{
        public static void main(String[] args) 
        {
                Scanner sc = new Scanner(System.in);
                
                System.out.println("Enter the sentence : ");
                String sentence = sc.nextLine();
                
                // utility class which seperates words in sentence, based on delimiter 
                StringTokenizer st = new StringTokenizer(sentence, " ");
                
                String answer = "";
                while(st.hasMoreElements())
                {
                        String word = st.nextToken();
                        
                        // check whether word length is greater 2
                        if(word.length() > 2)
                                answer += word.charAt(2);
                }
                
                System.out.println(answer);
        }
}

refer the below image for indentation.

OUTPUT:


Related Solutions

Write a short program that asks the user for a sentence and prints the result of...
Write a short program that asks the user for a sentence and prints the result of removing all of the spaces. Do NOT use a built-in method to remove the spaces. You should programmatically loop through the sentence (one letter at a time) to remove the spaces.
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> c++ project. need help.
c# language Write a program that takes in a number from the user. Then it prints...
c# language Write a program that takes in a number from the user. Then it prints a statement telling the user if the number is even or odd. If the number is odd, it counts down from the number to 0 and prints the countdown on the screen, each number on a new line. If the number is even, it counts down from the number to 0, only even numbers. For example, if the user enters 5, the output will...
in.java Write a program that reads an integer from the user and prints a rectangle of...
in.java Write a program that reads an integer from the user and prints a rectangle of starts of width 5 3 and height N. Sample run 1: Enter N: 5 *** *** *** *** *** Bye Sample run 2: Enter N: 8 *** *** *** *** *** *** *** *** Bye Sample run 3: Enter N: 2 *** *** Bye Sample run 4: Enter N: -2 Bye
Write a program that uses a while statement to read integers from the user and prints...
Write a program that uses a while statement to read integers from the user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters 999. The average should be output with 4 digits of precision. c++ please ASAP
in java Write an application that gets two numbers from the user and prints the sum,...
in java Write an application that gets two numbers from the user and prints the sum, product, difference and quotient of the two numbers in a GUI.
Write a program that accept an integer input from the user and display the least number...
Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s. Test your solution using this samples] a. Input: 250 Output: 1x200s, 1x50s b. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s c. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s d. Input: 19 Output: 1x10s, 1x5s, 4x1s ​[Hints] o Use division to determine the number of occurrence of each element (i.e. 200, 100)...
Using Matlab do the following Write a program that will accept a number from the user...
Using Matlab do the following Write a program that will accept a number from the user and: Check if the number between 50 and 100both inclusive. If yes print a comment. If not print a warning. The program sums the inserted values This process continues until the user inserts the number 999 . At this point the program quits and prints the result of (2)
write a python program that reads a sentence and identifies a word from an existing glossary...
write a python program that reads a sentence and identifies a word from an existing glossary and states the meaning of the word
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT