Computer Applications
Consider a String:
THE COLD WATER AND THE HOT WATER GLASSES ARE KEPT ON THE TABLE
Write a program by using scanner class to enter the string and display the new string after removing repeating token 'THE'. The new string is:
COLD WATER AND HOT WATER GLASSES ARE KEPT ON TABLE
Java
Input in Java
4 Likes
Answer
import java.util.Scanner;
public class KboatRemoveThe
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence ending with a space & terminating with (.):");
while(in.hasNext()) {
String word = in.next();
if (word.equals("."))
break;
else if (!word.toUpperCase().equals("THE"))
System.out.print(word + " ");
}
}
}Variable Description Table
Program Explanation
Output

Answered By
3 Likes
Related Questions
Write a program by using scanner class to accept a set of positive and negative numbers randomly. Print all the negative numbers first and then all the positive numbers without changing the order of the numbers.
Write a program to generate random numbers between 1 to N by using scanner class taking N from the console.
Using scanner class, write a program to input a string and display all the tokens of the string which begin with a capital letter and end with a small letter.
Sample Input: The capital of India is New Delhi
Sample Output: The India New DelhiWrite a program to input a string by using scanner class. Display the new string which is formed by the first character of each string.
Sample Input: Automated Teller Machine
Sample Output: ATM