Question 42 : Write a program in Java to break a sentence entered by the user into its words and find the no. of vowels and consonants in each.
Java Program :
import java.io.*;
class vowels
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,j,b=0,v=0,c=0,space=0;
char k,d='a';
String a,s="";
System.out.print("Enter the sentence : ");
a=br.readLine();
System.out.print("\n");
for(i=0;i<=a.length()-1;i++)
{
k=a.charAt(i);
if(k==' ')
{
check(i-1,b,a);
b=i+1;
}
if(k!=' ')
space=space+1;
}
if(space!=a.length())
check(a.length()-1,b,a);
if(space==a.length())
check(a.length()-1,0,a);
System.out.println("Thank you for using this short program");
}
static void check(int z,int y,String x)
{
int j,v=0,c=0;
char d;
String s="";
for(j=y;j<=z;j++)
{
d=x.charAt(j);
s=s+d;
if(d=='a' || d=='A' || d=='e' || d=='E' || d=='i' || d=='I' || d=='o' || d== 'O' || d=='u' || d=='U')
v=v+1;
else
c=c+1;
}
System.out.println(s+" = No. of vowels = "+v+" & No. of consonants = "+c);
System.out.print("\n");
}
}
Java Program :
import java.io.*;
class vowels
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,j,b=0,v=0,c=0,space=0;
char k,d='a';
String a,s="";
System.out.print("Enter the sentence : ");
a=br.readLine();
System.out.print("\n");
for(i=0;i<=a.length()-1;i++)
{
k=a.charAt(i);
if(k==' ')
{
check(i-1,b,a);
b=i+1;
}
if(k!=' ')
space=space+1;
}
if(space!=a.length())
check(a.length()-1,b,a);
if(space==a.length())
check(a.length()-1,0,a);
System.out.println("Thank you for using this short program");
}
static void check(int z,int y,String x)
{
int j,v=0,c=0;
char d;
String s="";
for(j=y;j<=z;j++)
{
d=x.charAt(j);
s=s+d;
if(d=='a' || d=='A' || d=='e' || d=='E' || d=='i' || d=='I' || d=='o' || d== 'O' || d=='u' || d=='U')
v=v+1;
else
c=c+1;
}
System.out.println(s+" = No. of vowels = "+v+" & No. of consonants = "+c);
System.out.print("\n");
}
}
COMPLICATED ONE
ReplyDeleteThat's why it is named so.
DeleteNice................
ReplyDeleteBasic C Program for Computer Programmer who want to learn. If you have simple wish you may visit. To get all update stay with us.
Outline:
• Language: C and Simscript.
• if (Condition) statement and Nested if statement is used to determine the given number is positive, negative, even or odd. Another way we solve this program using if-else-if ladder.
• When the given condition or expression is true the statement associated with it executed.
To know details:
http://www.secufoon.com/write-a-c-program-for-determining-a-number-is-positive-negative-even-or-odd/