Interview Question


Country: Bangladesh
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class VowelSpecialChar {
public static void main(String args[]){

String testStr="This is a test sentence, gb good luck.";
String [] arrStr= testStr.split(" ");
Pattern p= Pattern.compile("[aeiou]");
Pattern p2= Pattern.compile("[^a-zA-Z0-9]");
int count=0;

for (int i=0;i<arrStr.length;i++){

Matcher match = p.matcher(arrStr[i]);


if(match.find())
{
count++;
System.out.println(arrStr[i]);
}



}

for (int i=0;i<arrStr.length;i++){

Matcher match2 = p2.matcher(arrStr[i]);
if (match2.find()){

System.out.println("found character: "+match2.group());
}

}

System.out.println("Count words of having vowels is: "+count);

}

}

- Rajkumari November 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thanks dear...but need total words which contain more than 1 vowels not total vowels in the sentence.

- maria November 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

change the following code
//////
if(match.find())
{
count++;
System.out.println(arrStr[i]);
}

///////

to

if(match.find())
{
if(match.find(match.start()+1)){
count++;
System.out.println(arrStr[i]);
}
}



Thanks..
Chenna Eda

- Anonymous December 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

suggest me if i can make my code better. Can i do this using enum?

public static void countvowel(String query)
{
String result="";

String[] word=query.split(" ");

for(int i=0;i<word.length;i++)
{
int c=count(word[i]);
if(c>=2)
{
System.out.println(word[i]);
result=result+" "+word[i];
}
}


String[] num=result.split(" ");
int val=num.length-1;

System.out.println("Total number of words which contain more than one vowel : "+val);
}

public static int count(String query)
{
Vowel v = null;
int count=0;

for(int i=0;i<query.length();i++)
{
switch(query.charAt(i))
{
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' : {count++;
break;}
}
}

return count;
}

- Anonymous December 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.test.me;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class FindVowels {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Character> vovelList = new ArrayList<>();
vovelList.add('a');
vovelList.add('e');
vovelList.add('i');
vovelList.add('o');
vovelList.add('u');
ArrayList<String> finalStrin = new ArrayList<>();
BufferedReader bufRead = new BufferedReader(new InputStreamReader(System.in));
try {
String s = bufRead.readLine();
String[] str = s.split(" ");
for(int i=0;i<str.length;i++){
char[] ch =str[i].toCharArray();
int count = 0;
for(int j = 0;j<ch.length;j++){
if(vovelList.contains((Character)ch[j])){
count++;
}
if(count>1){
finalStrin.add(str[i]);
break;
}
}
}
for(String strl: finalStrin){
System.out.print(strl);
System.out.print("\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

- SkullCrusher February 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Vowels {
public static void main(String[] args) {
String s;
String n;
char c;
char sp[]={'!','@','#','$','%','^','&','*','(',')'};
char ow[]={'a','e','i','o','u'};
char ch[]=new char[10];
char msp[]=new char[10];
int l,oc=0,nlo=0,mspc=0;
Scanner sc=new Scanner(System.in);
System.out.print("enter the given string");
s=sc.nextLine();
StringTokenizer st=new StringTokenizer(s," ");
while(st.hasMoreElements())
{
n=st.nextElement().toString();
ch=n.toCharArray();
oc=0;
for(int i=0;i<ch.length;i++)
{
for(int j=0;j<5;j++)
{
if(ch[i]==ow[j])
{
oc++;
}
}
for(int k=0;k<sp.length;k++)
{
if(ch[i]==sp[k])
{
msp[mspc]=sp[k];
mspc++;
}
}
}
if(oc>=2)
nlo++;

}
System.out.printf("no of lines contians more than 2 vowels"+nlo);
for(int k=0;k<mspc;k++)
System.out.println("no of special matching characters"+msp[k]);

}
}
sample o/p:enter the given stringhello ram charan@ raki# gani%
no of lines contians more than 2 vowels4no of special matching characters@
no of special matching characters#
no of special matching characters%

- ram97 March 05, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More