Question d’entretien chez LinkedIn

Check if a String contains a number or not

Réponses aux questions d'entretien

Utilisateur anonyme

29 juil. 2014

String s= "abcabddd1"; char[] ch=s.toCharArray(); for(char c:ch){ if(Character.isDigit(c)){ break; } }

2

Utilisateur anonyme

25 juil. 2014

ATOI conversion .

3

Utilisateur anonyme

19 août 2014

// Remember that the character "0" has the ASCII value 48 // so if we subtract 48 from every ASCII value we got // and find a value between 0 and 9, means we got our number ;) char s[] = "abc123def456g7h8i90"; for (int i = 0; i = 0 && diff < 10) { return true; } }

Utilisateur anonyme

5 sept. 2014

C++ solution: bool containsNumber(string s) { if (s.find_first_of("0123456789") != string::npos) { return true; } return false; }

Utilisateur anonyme

10 oct. 2014

//Check if a String contains a number or not function find_digit(str) { var search_result = str.search(/[0-9]/g); if (search_result < 0) { // or return false return console.log("nothing"); } else { // or return true return console.log(str[search_result]); } }