Program
public class Main {
public static void main(String[] args) {
String test = "@sateeshm.com 123456";
char[] ch = test.toCharArray();
int letter = 0;
int space = 0;
int num = 0;
int otherchat = 0;
for(int i = 0; i < test.length(); i++){
if(Character.isLetter(ch[i])){
letter ++ ;
}
else if(Character.isDigit(ch[i])){
num ++ ;
}
else if(Character.isSpaceChar(ch[i])){
space ++ ;
}
else{
otherchat ++;
}
}
System.out.println("The string is : @sateeshm.com 123456");
System.out.println("letter: " + letter);
System.out.println("space: " + space);
System.out.println("number: " + num);
System.out.println("other: " + otherchat);
}
}
Output:
The string is : @sateeshm.com 123456
letter: 11
space: 1
number: 6
other: 2
For latest job updates join Telegram Channel: https://t.me/sateeshm