logo

El caràcter de Java és el mètode alfabètic ().

El mètode isAlphabetic(intcodePoint) de la classe Character determina si el caràcter especificat és un alfabet o no.

Un caràcter es considera un alfabet si té les característiques següents:

  • LLETRA MAJÚSCULA
  • LLETRA MINÚSCULA
  • TITLECASE_LETTER
  • MODIFIER_LETTER
  • OTHER_LETRAS
  • LETTER_NUMBER o
  • Altres alfabets definits per l'estàndard Unicode.

Sintaxi

 public static Boolean isAlphabetic(int codePoint) 

Paràmetre

codePoint : És el personatge a provar.

xacal vs llop

Valor de retorn

El mètode isAlphabetic(intcodePoint) retorna true si el caràcter és un caràcter de l'alfabet Unicode. En cas contrari, aquest mètode retorna el fals.

Exemple 1

 public class JavaCharacterisAlphabeticExample1 { public static void main(String[] args) { char codepoint1 = '0'; char codepoint2 = '1'; boolean b1 = Character.isAlphabetic(codepoint1); boolean b2 = Character.isAlphabetic(codepoint2); System.out.println('The returned value for the first character is given as:'+' '+b1); System.out.println('The returned value for the first character is given as:'+' '+b2); } } 
Prova-ho ara

Sortida:

 The returned value for the first character is given as: false The returned value for the first character is given as: false 

Exemple 2

 public class JavaCharacterisAlphabeticExample2 { public static void main(String[] args) { // Initialize the codepoints int codepoint1 = 87; int codepoint2 = 49; int codepoint3 = 63; // Check if the first codepoint is alphabet or not. boolean checkAlp1 = Character.isAlphabetic(codepoint1); if(checkAlp1){ System.err.print('Codepoint ''+codepoint1+'' is an alphabet.
'); } else{ System.out.print('Codepoint ''+codepoint1+'' is not an alphabet.
'); } // Check if the second codepoint is alphabet or not. boolean checkAlp2 = Character.isAlphabetic(codepoint2); if(checkAlp2){ System.err.print('Codepoint ''+codepoint2+'' is an alphabet.
'); } else{ System.out.print('Codepoint ''+codepoint2+'' is not an alphabet.
'); } // Check if the third codepoint is alphabet or not. boolean checkAlp3 = Character.isAlphabetic(codepoint3); if(checkAlp3){ System.err.print('Codepoint ''+codepoint3+'' is an alphabet.
'); } else{ System.out.print('Codepoint ''+codepoint3+'' is not an alphabet.
'); } } } 
Prova-ho ara

Sortida:

 Codepoint '87' is an alphabet. Codepoint '49' is not an alphabet. Codepoint '63' is not an alphabet. 

Exemple 3

 public class JavaCharacterisAlphabeticExample3 { public static void main(String[] args) { char codepoint1 = '1'; char codepoint2 = 'A'; char codepoint3 ='B'; boolean b1 = Character.isAlphabetic(codepoint1); boolean b2 = Character.isAlphabetic(codepoint2); boolean b3 = Character.isAlphabetic(codepoint3); System.out.println('The returned value for the first character is given as:'+' '+b1); System.out.println('The returned value for the second character is given as:'+' '+b2); System.out.println('The returned value for the third character is given as:'+' '+b3); } } 
Prova-ho ara

Sortida:

 The returned value for the first character is given as: false The returned value for the second character is given as: true The returned value for the third character is given as: true