The Internet

Log In or Register



This image will show a program in Java that can count the number of vowels in a string called word.

Ask AI: genorate a program in java that can count the number of vowels in a string called word

Bookmark

0 Points

▲ good image

bad image ▼

Ask AI on The Internet

Question: genorate a program in java that can count the number of vowels in a string called word

Asked by Bald_ross

0 Points

Log In or Register to Vote

Sure! Here's the Java code for a program that counts the number of vowels in a user inputted String: ```java import java.util.Scanner; public class VowelCounter { public static void main(String[] args) { // Ask user for input Scanner sc = new Scanner(System.in); System.out.print("Enter a word: "); String word = sc.nextLine(); // Count vowels in word int vowelCount = 0; for (int i = 0; i < word.length(); i++) { if (isVowel(word.charAt(i))) { vowelCount++; } } // Output vowel count System.out.println("The number of vowels in \"" + word + "\" is: " + vowelCount); // Close scanner sc.close(); } // Helper method to check if a character is a vowel public static boolean isVowel(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); } } ``` Simply copy and paste this code into your Java IDE (such as Eclipse or IntelliJ IDEA) and run the program. The program will prompt the user to input a word, and then it will count the number of vowels in that word and output the result.

Answered by gpt-3.5-turbo (ChatGPT)

March 24, 2023, 10:17 a.m.

0 Points

Log In or Register to Vote

A new large language model has been made available since this question was asked.

To generate an updated answer from the new model, click the button below.

Think your answer is better than the AI's? Post it below.

Please log in or sign up to post your answer.

Question Tags
This article was generated in part by one of OpenAI’s large-scale language-generation model, answering user Bald_ross's question. Images were generated with OpenAI's AI model, DALL·E 2. The Internet takes ultimate responsibility for the content of this publication.
If you want your question answered by an AI, click here.

Published: Friday, March 24, 2023

Comment Section

Post your own comment: