-1

As I have mentioned on the title above I need to know how to check each of the characters inside a String as follows:

  1. check if the string is less than 3 character.
  2. check if the string contains digits.
  3. check if a single word of string has no vowels.

I've been searching for the exact example but I couldn't find one.

xenteros
  • 15,586
  • 12
  • 56
  • 91
Haider Abdullah
  • 111
  • 2
  • 13
  • 1
    Possible duplicate of [How to check if all characters in a String are all letters?](http://stackoverflow.com/questions/20569685/how-to-check-if-all-characters-in-a-string-are-all-letters) – Matthew Brzezinski Dec 13 '16 at 18:58
  • Did you tried anything? Please post some code snippet which you have tried. – SachinSarawgi Dec 13 '16 at 18:59
  • First of all, I'm new in JAVA or programming, in general, I tried to read some examples and other posts but I can't still figure it out because those posts I've read are some kind of advanced codes so I thought of posting here and hoping to get a better explanation and easy methods. – Haider Abdullah Dec 13 '16 at 19:11
  • 1
    @HaiderAbdullah check my answer. If it's helpful, just click on the gray tick below my answer's score – xenteros Dec 13 '16 at 19:15

1 Answers1

1

Follow those steps:

String s = "mystring";
s.length() < 3 // expression which says if it's smaller than 3.
s.matches(".*[0-9].*") //expression which says if there are digits in the string
s.matches("\b[^aeiouAEIOU ]+\b") //expression which says if there are no vovels

To check if yourString matches all those conditions:

if (myString.length() < 3 && myString.matches(".*[0-9].*") 
    && myString.matches("\b[^aeiouAEIOU ]+\b")) {
   //matches all
}
xenteros
  • 15,586
  • 12
  • 56
  • 91
  • let me try this one and I will get back to you later. thank you very much I really appreciate your help. – Haider Abdullah Dec 13 '16 at 19:21
  • I'm still fixing my laptop it's hanging I will inform you later after I fix this. – Haider Abdullah Dec 13 '16 at 19:42
  • Hi, I'm having trouble with this line of codes.length() < 3 should I end it with the semi-colon? – Haider Abdullah Dec 13 '16 at 20:01
  • Sir, I'm just getting confused about your code arrangement, mostly this part "s.length() < 3" I used them now and it didn't work. I don't know if I'm just having a problem on how I followed it or you really need to specify it properly. Sorry sir I'm just a starter. – Haider Abdullah Dec 13 '16 at 20:12
  • @HaiderAbdullah I made a typo. Check now. There was a misspelling in the length() – xenteros Dec 13 '16 at 20:25