Tuesday, March 17, 2020

Java Program On String And Convert First Letter Of Each Words Uppercase

For Details of The Program: CLICK HERE


import java.io.*;
class Q3
{
String s2,s1;
int len, v;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

void accept( ) throws Exception
{
System.out.print("\nEnter the sentence:");
s1=br.readLine();
check();
}
void check( )
{
int c;
len=s1.length()-1;
if(s1.charAt(len)=='.' || s1.charAt(len)=='?')
{
s1=s1.substring(0,len);
s1=modified(s1);
System.out.println("\nModified sentence:"+s1);
System.out.println("\nWord Vowels Consonents"); 
while(true)

{
len=s1.indexOf(" ");
if(len<=0)
break;
s2=s1.substring(0,len);
s1=s1.substring(len+1);
v=vowel(s2);
System.out.println(s2 + "   " + v + " " + (s2.length()-v));
}
v=vowel(s1); 
System.out.println(s1 + "   " + v + " " + (s1.length()-v)); 
}
else
System.out.println("\nInvalid Entry");
}
String modified(String str)
{
String s1="";
int j,size;
size=str.length()-1;
for(j=0;j<=size;j++)
{
if(j==0)

s1=s1+Character.toUpperCase(str.charAt(j)); else if(str.charAt(j)==' ') {

s1=s1+" "+Character.toUpperCase(str.charAt(j+1));
j++;
}
else
s1=s1+Character.toLowerCase(str.charAt(j));
}
return s1;
}
int vowel(String s1)
{
int j,c=0,size;
size=s1.length()-1;
s1=s1.toUpperCase();
for(j=0;j<=size;j++)
{
switch(s1.charAt(j))
{
case 'A':

case 'E':
case 'I':
case 'O':
case 'U':
c++;
}
}
return c;
}
public static void main(String args[]) throws Exception
{
Q3 one=new Q3();
one.accept();
}
}

Variable description


Type
Variable Name
Purpose
Scope
String
s1
Holds the
Entire programm


sentence

String
S2
Holds each word
Entire programm


from the



sentence

int
j
Loop control
Modified and


variable
vowel function
BufferedReader
br
Input object
Entire program
Algorithm




Step 1: Create the variables
Step 2: Take the sentence and store in s1
Step 3: Modify the sentence with each character starts with capital letter
Step 4: break the sentence into words
Step 5: Count the number of vowels in each word


Step 6: Display the word, vowel and consonants (length – vowel) in the word

2015 Computer Practical Paper: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner