Write a java program to check vowel or consonant


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  1. import java.util.Scanner;
  2. public class JavaExcercise {
  3.  
  4.  
  5. public static void main(String[] args)
  6. {
  7. Scanner in = new Scanner(System.in);
  8.  
  9. System.out.print("Enter any alphabet: ");
  10. String input = in.next().toLowerCase();
  11.  
  12. boolean uppercase = input.charAt(0) >= 65 && input.charAt(0) <= 90;
  13. boolean lowercase = input.charAt(0) >= 97 && input.charAt(0) <= 122;
  14. boolean vowels = input.equals("a") || input.equals("e") || input.equals("i")
  15. || input.equals("o") || input.equals("u");
  16.  
  17. if (input.length() > 1)
  18. {
  19. System.out.println("Error. Not a single character.");
  20. }
  21. else if (!(uppercase || lowercase))
  22. {
  23. System.out.println("Error. Not a letter. Enter uppercase or lowercase letter.");
  24. }
  25. else if (vowels)
  26. {
  27. System.out.println("Input letter is Vowel");
  28. }
  29. else
  30. {
  31. System.out.println("Input letter is Consonant");
  32. }
  33. }
  34. }

Result

java techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.