Computer Science, asked by rachnasetia1412, 1 year ago

Write a program in java to accept a word /string . Counting all the letters excluding the vowels present in the word / string and display the result

Answers

Answered by muakanshakya
22
\Huge\textbf{Answer:}

import java.util.*;

class str
{
public static void main(String args[])

{

int count =0;
Scanner sc = new Scanner (System .in);
System.out.println("Enter a string:");

String str = sc nextLine();

int len = str . length();

for(int i=0; i<len; i++)
{

char ch = str . charAt(i);

if(ch=='A'||ch=='a'|| ch=='E' || ch=='e' || ch=='I'|| ch=='i'|| ch=='O'|| ch=='o'|| ch=='U'|| ch=='u')

{

continue ;

}

else

{

count++;

}

}

System.out.println("The total no. of letters present in"+ str + "are="+ count);

}

}

\Large \textbf{Out}\textbf{put}

Enter a string : Good

The total no of letters present in Good are = 2

__________________________________

\begin{tabular}{|c|l|} \bf Variable &amp; \bf Description\\ \cline{1-2}int i&amp; to iterate the for $\rm lo op$ \\ &amp; for extracting characters purpose \\ \cline{1-2}int count &amp; to count the no of letters except vowels \\ \end{tabular}
Attachments:
Similar questions