Computer Applications
Write a program to input a sentence. Convert the sentence into upper case letters. Display the words along with frequency of the words which have at least a pair of consecutive letters.
Sample Input: MODEM IS AN ELECTRONIC DEVICE
Sample Output:
MODEM
DEVICE
Number of words containing consecutive letters: 2
Java
Java String Handling
97 Likes
Answer
import java.util.Scanner;
public class KboatStringConsecutive
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the string: ");
String str = in.nextLine();
str = str.toUpperCase();
str += " ";
String word = "";
int count = 0;
int len = str.length();
for (int i = 0; i < len; i++) {
if (str.charAt(i) == ' ') {
int wordLen = word.length();
for (int j = 0; j < wordLen - 1; j++) {
if (word.charAt(j) + 1 == word.charAt(j + 1)) {
count++;
System.out.println(word);
break;
}
}
word = "";
}
else {
word += str.charAt(i);
}
}
System.out.println("Number of words containing consecutive letters: " + count);
}
}
Variable Description Table
Program Explanation
Output
Answered By
31 Likes
Related Questions
Write a program to accept a word (say, BLUEJ) and display the pattern:
J
E E
U U U
L L L L
B B B B BSpecial words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.Write a program to accept a word. Check and display whether the word is a palindrome or only a special word or none of them.
Write a program to accept a word (say, BLUEJ) and display the pattern:
B L U E J
B L U E
B L U
B L
BWrite a program to accept a string. Convert the string into upper case letters. Count and output the number of double letter sequences that exist in the string.
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE"
Sample Output: 4