WAP to input a string and count the number of Consonants and replace the vowels with a "@"
Answers
Answer:
Explanation:
Algorithm
- Define a string.
- Convert the string to lower case so that comparisons can be reduced. ...
- If any character in string matches with vowels (a, e, i, o, u ) then increment the vcount by 1.
- If any character lies between 'a' and 'z' except vowels, then increment the count for ccount by 1.
- Print both the counts.
your answer is :
import java.util.Scanner;
public class frequencyCount
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int consonant=0;
String newstr="";
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)== 'A' || str.charAt(i)== 'E' || str.charAt(i)== 'I' || str.charAt(i)== 'O' || str.charAt(i)== 'U' ||str.charAt(i)== 'a' || str.charAt(i)== 'e' || str.charAt(i)== 'i' || str.charAt(i)== 'o' || str.charAt(i)== 'u' )
{
newstr=newstr+'@';
}
else
{
consonant++;
newstr=newstr+str.charAt(i);
}
}
System.out.println("number of consonants = "+consonant);
System.out.println("new String after the vowel is replaced with @ = "+newstr);
}
}