Java String Manipulation 28th Jan Practice 1 - to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character
Java Program to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char a;
System.out.println("Enter a character");
a = in.next().charAt(0);
if(Character.isLetter(a)){
System.out.println("Character "+ a+ " is letter");
if(Character.isUpperCase(a)){
System.out.println(Character.toLowerCase(a));
}
else
System.out.println(Character.toUpperCase(a));
}
else if(Character.isDigit(a)){
System.out.println(a+" is a digit");}
else
System.out.println(a+" is a special character");
}
}
Comments
Post a Comment