Dain1234 / Java-Programming

0 stars 0 forks source link

Vowels consonants #34

Open Dain1234 opened 1 year ago

Dain1234 commented 1 year ago

package com.dain.logics;

import java.util.Scanner;

public class vowelconsonantcount { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the String:"); String s = sc.nextLine(); int len = s.length();

    int c = 1, v = 1;

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

        if (s.charAt(i) == 'a' || s.charAt(i) == 'e' || s.charAt(i) == 'i' || s.charAt(i) == 'o'
                || s.charAt(i) == 'u' || s.charAt(i) == 'A' || s.charAt(i) == 'E' || s.charAt(i) == 'I'
                || s.charAt(i) == 'O' || s.charAt(i) == 'U') {

            v++;

        }
        else {
            c++;
        }
    }
    System.out.println("vowel count:" + (v - 1));
    System.out.println("consonant count:" + (c - 1));

}

}