brilliant_moves

OrksVowelsQuestion.java

Feb 3rd, 2020
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.97 KB | None | 0 0
  1. /*
  2. ork
  3. asked in Computers & Internet
  4. Programming & Design · 3 hours ago
  5. string methods to determine whether the string has at least two occurrences of the vowels?
  6.  
  7. 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".
  8.  
  9. ** Constraints: only take strings with lowercase letters. **
  10.  
  11. Example: Please input a string: hello
  12.  
  13. true
  14.  
  15. Please input a string: abundant
  16.  
  17. true
  18.  
  19. Please input a string: sync
  20.  
  21. false
  22. Updated 3 hours ago:
  23.  
  24. USE Java  String Methods
  25.  
  26. */
  27.  
  28. import java.util.Scanner;
  29.  
  30. public class OrksVowelsQuestion {
  31.  
  32.     /**
  33.       * OrksVowelQuestion.java by Chris Clarke, 03.02.2020 for Yahoo! Answers.
  34.       * Copyright © Chris Clarke 2020
  35.       * Unauthorized use of this code is prohibited, and will
  36.       * result in legal action amounting to a fine, or, in certain cases, prison.
  37.       * Copy and paste at your peril! You have been warned.
  38.       */
  39.  
  40.     public static void main (String[] args) {
  41.  
  42.         Scanner keybd = new Scanner (System.in);    // create scanner to read keyboard input
  43.         final String vowels = "aeiou";              // string contains all vowels
  44.         String input;                               // to hold user input
  45.         int vCount = 0;                             // to count number of vowels found in input
  46.  
  47.         System.out.print ("Please input a string: ");   // prompt user
  48.         input = keybd.nextLine();                       // get user input
  49.  
  50.         if (!input.equals (input.toLowerCase())) {
  51.             System.out.println ("Input wasn't all lower case characters!");
  52.             System.out.print ("Converting to lower case: ");
  53.             input = input.toLowerCase();
  54.             System.out.println (input);
  55.         }
  56.  
  57.         for (int i=0; i<input.length(); i++) {
  58.             if (vowels.indexOf (input.charAt (i)) != -1) {
  59.                 vCount++;
  60.             }
  61.         }
  62.  
  63.         System.out.print ("Has 2 or more vowels? ");
  64.         if (vCount>=2) {
  65.             System.out.println ("true");
  66.         } else {
  67.             System.out.println ("false");
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment