Friday, 20 April 2018


//wap to check how many  digit chars space chars alphabets and  special chars in a sring?

public class StringTest {

public static String checkStringEveryThing(String s1)
{
int digit=0;
int space=0;
int letter=0;
int specialchar=0;

char[] ch = s1.toCharArray();
for(char ct:ch)
{
if(Character.isDigit(ct))
{
digit++;
}
else if(Character.isSpace(ct))
{
space++;
}

else if(Character.isLetter(ct))
{
letter++;
}


else
{
specialchar++;
}




}
return "DigitChar="+digit+" Letter="+letter+"Special char="+specialchar+"SpaceChar="+space;

}
public static void main(String[] args) {
String s2 = StringTest.checkStringEveryThing("Govind ##### Ballabh @@@@@ khan $$$$$$ 1992 Bihar madhubani  847231");
    System.out.println(s2);

}

}

No comments:

Post a Comment