Wednesday, 18 November 2020

Java program to accept a String and display the number of Vowels and Number of constants present in it.

import java.util.*;

public class STRING

{

public static void main(String args[])

{

Scanner in=new Scanner (System.in);

String s="",s1; int Length,i,vowel=0,constant=0;

char ch;

s1=s.toLowerCase();

System.out.println("Enter a Word");

s=in.nextLine();

Length=s.length();

for(i=0;i<Length;i++)

{

ch=s.charAt(i);

if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')

vowel++;

else 

constant++;

}

System.out.println("The Number of Vowels in "+s+" is "+vowel);

System.out.println("The Number of Constants in "+s+" is "+constant);

}

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...