Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
177 views

Isc Computer Programs

This Java code accepts a sentence from the user as input, capitalizes the first letter of each word, and then analyzes and prints the number of vowels and consonants in each word. It uses loops and conditional statements to iterate through the input, check for spaces and punctuation to identify words, call a method to check each letter for vowels, and tally and print the counts.

Uploaded by

subhashissohail
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views

Isc Computer Programs

This Java code accepts a sentence from the user as input, capitalizes the first letter of each word, and then analyzes and prints the number of vowels and consonants in each word. It uses loops and conditional statements to iterate through the input, check for spaces and punctuation to identify words, call a method to check each letter for vowels, and tally and print the counts.

Uploaded by

subhashissohail
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.io.

*;
class ISC_2015_3
{
public static void main(String args[])throws IOException
{
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)
);
ISC_2015_3 obj=new ISC_2015_3();
int ct=0;
String s="";
int l=0;
while(ct!=1)
{
System.out.println("Enter a sentence");
s=stdin.readLine();
s=s.trim();
l=s.length();
if(s.charAt(l-1)=='.'||s.charAt(l-1)=='?')
ct++;
}
String s1="";
s=" "+s;
char ab;
char cd;
for(int i=0;i<l;i++)
{
ab=s.charAt(i);
cd=s.charAt(i+1);
if((ab==32)&&(cd>=97&&cd<=122))
{
s1=s1+" "+((char)(cd-32));
i++;
}
else
s1=s1+ab;
}
s1=s1.trim();
System.out.println(s1);
String s2="";
int c=0,d=0;
System.out.println("Word\t\t Vowels Consonants");
for(int i=0;i<s1.length();i++)
{
ab=s1.charAt(i);
if(ab!=32)
{
if(obj.vowels(ab))
c=c+1;
else
d=1+d;
s2=s2+ab;
}
else
{
System.out.println(s2+"\t\t"+c+"\t"+d);
s2="";
c=0;
d=0;
}
}

}
boolean vowels(char ab)
{
if(ab=='A'||ab=='a'||ab=='E'||ab=='e'||ab=='I'||ab=='i'||ab=='o'||ab=='O
'||ab=='u'||ab=='U')
return true;
else
return false;
}
}

You might also like