Advertisement
ralphdc09

itf103.md-wk-11-wk-13.number02

May 15th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. package md.WK11toWK13;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class number02 {
  6.     public static void main(String[] args) {
  7.         Scanner ralph = new Scanner(System.in);
  8.  
  9.         System.out.print("Input a letter of the alphabet: ");
  10.  
  11. //        converts string input to lowercase for a more simple algorithm
  12.         String input = ralph.next().toLowerCase();
  13.  
  14.         boolean uppercase = input.charAt(0) >= 65 && input.charAt(0) <= 90;
  15.         boolean lowercase = input.charAt(0) >= 97 && input.charAt(0) <= 122;
  16.         boolean vowels = input.equals("a") || input.equals("e") || input.equals("i") || input.equals("o") || input.equals("u");
  17.  
  18. //        prints "error" when string input length is longer than 1 character
  19.         if (input.length() > 1) {
  20.             System.out.println("Error! Please enter a single character!");
  21.  
  22. //        prints "error" when string input is not a lowercase or uppercase letter
  23.         } else if (!(uppercase || lowercase)) {
  24.             System.out.println("Error! Please enter a lowercase or uppercase letter");
  25.  
  26. //         prints "vowels" when string input is a vowel letter
  27.         } else if (vowels) {
  28.             System.out.println("You input a Vowel letter");
  29.  
  30. //         prints "consonants" when string input is a consonant letter
  31.         } else {
  32.             System.out.println("You input a Consonant letter");
  33.         }
  34.     }
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement