Please reply fast.
How to write a program in java to take a String as input fron the user and print the word in the sentence which has the consecutive vowels present in the word ?
For example : Bear is eating deer.
Output : Bear eating deer
For example : Sky is dark.
Output : No consecutive vowels are present in the words.
Answers
import java.util.*;
import java.lang.*;
import java.io.*;
class myDemo {
public static boolean twoVowels(String s) {
String vowels = new String ("aeiou") ; int i,j;
for (i=0; i<s.length()-1; i++)
if (vowels.indexOf(s.charAt(i))>=0 && vowels.indexOf(s.charAt(i+1))>=0)
return true;
return false;
}
public static void main (String[] args) throws java.lang.Exception {
String str; Scanner inp ;
String delims = "[ ,.\'\"?!\\n\\t()]+";
inp = new Scanner (System.in);
str = inp.nextLine();
while (! str.isEmpty()) {
String []tokens = str.split(delims);
for (String t : tokens) {
if (t.length() > 1 && twoVowels(t)) System.out.print(t + " ");
}
System.out.println();
str = inp.nextLine();
}
}
}
This works.