Check whether a character is an alphabet or not.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean av = false;
System.out.println("Enter the Alphabet ");
char ch = sc.next().charAt(0);
for(int i = 'A'; i<='Z'; i++){
if(ch == i){
av = true;
break;
}
}
if(av ==false){for(int i = 'a'; i<='a'; i++){
if(ch == i){
av = true;
break;
}
}}
if(av==true){System.out.println(ch + " is an Alphabet");}
else{System.out.println(ch + " is not an Alphabet");}
}
}
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean av = false;
System.out.println("Enter the Alphabet ");
char ch = sc.next().charAt(0);
for(int i = 'A'; i<='Z'; i++){
if(ch == i){
av = true;
break;
}
}
if(av ==false){for(int i = 'a'; i<='a'; i++){
if(ch == i){
av = true;
break;
}
}}
if(av==true){System.out.println(ch + " is an Alphabet");}
else{System.out.println(ch + " is not an Alphabet");}
}
}
Comments
Post a Comment