count all the vowels in the given string in java.

 import java.util.*;

public class code
{
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("enter string=");
    String str=sc.nextLine();
    int c=0;
    for(int i=0; i<str.length(); i++){
        char ch=str.charAt(i);
        if(isvowel(ch)==true)
        c++;
    }
    System.out.println("total vowel are="+c);
    }
    public static boolean isvowel(char ch){
        if(ch=='a'|| ch=='A') return true;
        if(ch=='e'|| ch=='E') return true;
        if(ch=='i'|| ch=='I') return true;
        if(ch=='o'|| ch=='O') return true;
        if(ch=='u'|| ch=='U') return true;
        return false;
    }
}

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.