BrojSuglasnika

Broji suglasnike na osnovu unete recenice. (kao komentar su stavljeni delovi koda koji broje i samoglasnike, simbole itd. )
mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.4 kB
4
Indexable
Never
package yo;


import java.io.*;
import java.util.Scanner;

public class GFG {

	// Function to count number of vowels, consonant,
	
	static void countCharacterType(String str)
	{
		// Declare the variable vowels, consonant, digit
		// and special characters
		int samoglasnik = 0, suglasnik = 0;
//	    int specialChar = 0, digit = 0;
	
		// str.length() function to count number of
		// character in given string.
		for (int i = 0; i < str.length(); i++) {
			
			char ch = str.charAt(i);
	
			if ( (ch >= 'a' && ch <= 'z') ||
				(ch >= 'A' && ch <= 'Z') ) {
	
				// To handle upper case letters
				ch = Character.toLowerCase(ch);
	
				if (ch == 'a' || ch == 'e' || ch == 'i' ||
					ch == 'o' || ch == 'u')
					samoglasnik++;
				else
					suglasnik++;
			}
//			else if (ch >= '0' && ch <= '9')
//				digit++;
//			else
//				specialChar++;
		}
		
    // 	System.out.println("Broj samoglasnika: " + samoglasnik);
		System.out.println("Broj suglasnika: " + suglasnik);
	//  System.out.println("Brojevi: " + digit);
	//	System.out.println("Simboli: " + specialChar);
	}
	public static Scanner scan = new Scanner(System.in);
	static public void main (String[] args)
	{
		System.out.println("Unesite recenicu za koju zelite da znate broj suglasnika: ");
		System.out.println();
		String str = scan.nextLine();
		countCharacterType(str);
	}
}