Write a Java Program to Check Whether a Character is Alphabet or Not

Java Program to Check Whether a Character is Alphabet or Not

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Check Whether a Character is Alphabet or Not
Java Program to Check Whether a Character is Alphabet or Not

Write a Java Program to Check Whether a Character is Alphabet or Not

PROGRAM: Java Program to Check Whether a Character is Alphabet or Not

/* Java Program to Check Whether a Character is Alphabet or Not */

1: Java Program to Check Alphabet using if else

public class Alphabet {

public static void main(String[] args) {

char c = ‘*’;

if( (c >= ‘a’ && c <= ‘z’) || (c >= ‘A’ && c <= ‘Z’))
System.out.println(c + ” is an alphabet.”);
else
System.out.println(c + ” is not an alphabet.”);
}
}

2: Java Program to Check Alphabet using ternary operator

public class Alphabet {

public static void main(String[] args) {

char c = ‘A’;

String output = (c >= ‘a’ && c <= ‘z’) || (c >= ‘A’ && c <= ‘Z’)
? c + ” is an alphabet.”
: c + ” is not an alphabet.”;

System.out.println(output);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *