Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ork
- asked in Computers & Internet
- Programming & Design · 3 hours ago
- string methods to determine whether the string has at least two occurrences of the vowels?
- There is a string as input from the user. Then, use string methods to determine whether the string has at least two occurrences of the vowels. If the string indeed has two occurrences of the vowels, you should print "true". Otherwise, print "false".
- ** Constraints: only take strings with lowercase letters. **
- Example: Please input a string: hello
- true
- Please input a string: abundant
- true
- Please input a string: sync
- false
- Updated 3 hours ago:
- USE Java String Methods
- */
- import java.util.Scanner;
- public class OrksVowelsQuestion {
- /**
- * OrksVowelQuestion.java by Chris Clarke, 03.02.2020 for Yahoo! Answers.
- * Copyright © Chris Clarke 2020
- * Unauthorized use of this code is prohibited, and will
- * result in legal action amounting to a fine, or, in certain cases, prison.
- * Copy and paste at your peril! You have been warned.
- */
- public static void main (String[] args) {
- Scanner keybd = new Scanner (System.in); // create scanner to read keyboard input
- final String vowels = "aeiou"; // string contains all vowels
- String input; // to hold user input
- int vCount = 0; // to count number of vowels found in input
- System.out.print ("Please input a string: "); // prompt user
- input = keybd.nextLine(); // get user input
- if (!input.equals (input.toLowerCase())) {
- System.out.println ("Input wasn't all lower case characters!");
- System.out.print ("Converting to lower case: ");
- input = input.toLowerCase();
- System.out.println (input);
- }
- for (int i=0; i<input.length(); i++) {
- if (vowels.indexOf (input.charAt (i)) != -1) {
- vCount++;
- }
- }
- System.out.print ("Has 2 or more vowels? ");
- if (vCount>=2) {
- System.out.println ("true");
- } else {
- System.out.println ("false");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment