Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package md.WK11toWK13;
- import java.util.Scanner;
- public class number02 {
- public static void main(String[] args) {
- Scanner ralph = new Scanner(System.in);
- System.out.print("Input a letter of the alphabet: ");
- // converts string input to lowercase for a more simple algorithm
- String input = ralph.next().toLowerCase();
- boolean uppercase = input.charAt(0) >= 65 && input.charAt(0) <= 90;
- boolean lowercase = input.charAt(0) >= 97 && input.charAt(0) <= 122;
- boolean vowels = input.equals("a") || input.equals("e") || input.equals("i") || input.equals("o") || input.equals("u");
- // prints "error" when string input length is longer than 1 character
- if (input.length() > 1) {
- System.out.println("Error! Please enter a single character!");
- // prints "error" when string input is not a lowercase or uppercase letter
- } else if (!(uppercase || lowercase)) {
- System.out.println("Error! Please enter a lowercase or uppercase letter");
- // prints "vowels" when string input is a vowel letter
- } else if (vowels) {
- System.out.println("You input a Vowel letter");
- // prints "consonants" when string input is a consonant letter
- } else {
- System.out.println("You input a Consonant letter");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement