import java.io.*;
class StringVowel
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str1,str2="";
char ch;
int i,len;
public void show() throws Exception
{
System.out.println("Enter the Sentence:");
str1=br.readLine();
len=str1.length();
for(i=0;i < len;i++)
{
ch=str1.charAt(i);
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
break;
default: str2=str2+ch;
}
}
System.out.println("Modified string without vowels:"+str2);
}
public static void main(String args[]) throws Exception
{
StringVowel ob=new StringVowel ();
ob.show();
}
}
The entered string including vowels (may not contain vowel also) is stored in an object ‘str1’ of string class. Another string class object is kept in this program to hold the modified string values-without vowels. Each character is accessed and using ‘switch’, the character is checked for vowel or not. If the character is not a vowel then it is concatenated with the second string object. The same process is repeated for all characters of the entered string.
class StringVowel
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str1,str2="";
char ch;
int i,len;
public void show() throws Exception
{
System.out.println("Enter the Sentence:");
str1=br.readLine();
len=str1.length();
for(i=0;i < len;i++)
{
ch=str1.charAt(i);
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
break;
default: str2=str2+ch;
}
}
System.out.println("Modified string without vowels:"+str2);
}
public static void main(String args[]) throws Exception
{
StringVowel ob=new StringVowel ();
ob.show();
}
}
Related Post: BlueJ Programs on String/Sentence
Technical analysis of this program
The entered string including vowels (may not contain vowel also) is stored in an object ‘str1’ of string class. Another string class object is kept in this program to hold the modified string values-without vowels. Each character is accessed and using ‘switch’, the character is checked for vowel or not. If the character is not a vowel then it is concatenated with the second string object. The same process is repeated for all characters of the entered string.
i need Fibbonacci Number
ReplyDeleteFibonacci series program is already in my blog. Please search
ReplyDelete