Generation

code to explanationWed, 03 May 2023

import java.util.Scanner; public class Main { static Scanner console = new Scanner(System.in); public static void main(String[] args) { String ch; int count = 0; System.out.print("Enter Characters: "); ch = console.nextLine(); for(int i = 0; i < ch.length(); i++) { if(isVowel(ch.charAt(i))) { count++; } } System.out.println("Number of vowels: " + count); } public static boolean isVowel(char let) { if (let=='A' || let=='E' || let=='I' || let=='O' || let=='U' || let=='a' || let=='e' || let=='i' || let=='o' || let=='u' ) { return true; } else { return false; }}}

This code counts the number of vowels in a String.

Questions about programming?Chat with your personal AI assistant