๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java

[Java] ๋ฌธ์ž๊ฐ€ ์ˆซ์ž์ธ์ง€ ๋ฌธ์ž์ธ์ง€ ํŒ๋‹จํ•˜๊ธฐ (Character.isDigit(), Character.isLetter())

by Bhinney 2022. 12. 22.

๐Ÿ“์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ฅผ ํ’€๋‹ค๊ฐ€, ์œ ์šฉํ•˜๊ฒŒ ์“ด ๋ฉ”์„œ๋“œ๋ฅผ ์žŠ์ง€ ์•Š์œผ๋ ค๊ณ  ํฌ์ŠคํŒ… ํ•ด๋ณธ๋‹ค.


๐Ÿ“Ž ๋ฌธ์ž๊ฐ€ ์ˆซ์ž์ธ์ง€ ํŒ๋‹จ

  • ์•„๋ž˜์˜ ์„ค๋ช…์„ ์ฐธ์กฐํ•˜๋ฉด '1' ~ '9' ๊นŒ์ง€์˜ ์ˆซ์ž๊ฐ€ ๋“ค์–ด์˜ค๋ฉด true๊ฐ€ ๋ฐ˜ํ™˜๋œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.
/*
Determines if the specified character is a digit.
A character is a digit if its general category type, provided by Character.getType(ch), is DECIMAL_DIGIT_NUMBER.
Some Unicode character ranges that contain digits:
'\u0030' through '\u0039', ISO-LATIN-1 digits ('0' through '9')
'\u0660' through '\u0669', Arabic-Indic digits
'\u06F0' through '\u06F9', Extended Arabic-Indic digits
'\u0966' through '\u096F', Devanagari digits
'\uFF10' through '\uFF19', Fullwidth digits
Many other character ranges contain digits as well.
Note: This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the isDigit(int) method.

๋งค๊ฐœ๋ณ€์ˆ˜:
ch – the character to be tested.

๋ฐ˜ํ™˜:
true if the character is a digit; false otherwise.
*/

public static boolean isDigit(char ch) {
    return isDigit((int)ch);
}

 

๐Ÿ“Ž ๋ฌธ์ž๊ฐ€ ๋ฌธ์ž์ธ์ง€ ํŒ๋‹จ

  • ์•„๋ž˜์˜ ์„ค๋ช…์„ ์ฐธ์กฐํ•˜๋ฉด ๋Œ€๋ฌธ์ž, ์†Œ๋ฌธ์ž ๋“ฑ์˜ ๋ฌธ์ž๊ฐ€ ๋“ค์–ด์˜ค๋ฉด true๊ฐ€ ๋ฐ˜ํ™˜๋จ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.
/*
Determines if the specified character is a letter.
A character is considered to be a letter if its general category type, provided by Character.getType(ch), is any of the following:
  • UPPERCASE_LETTER
  • LOWERCASE_LETTER
  • TITLECASE_LETTER
  • MODIFIER_LETTER
  • OTHER_LETTER
Not all letters have case. Many characters are letters but are neither uppercase nor lowercase nor titlecase.
Note: This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the isLetter(int) method.

๋งค๊ฐœ๋ณ€์ˆ˜:
ch – the character to be tested.

๋ฐ˜ํ™˜:
true if the character is a letter; false otherwise.
*/

public static boolean isLetter(char ch) {
    return isLetter((int)ch);
}

โ„๏ธ ์ถœ๋ ฅ ์˜ˆ์‹œ

public class CheckCharacter {
   public static void main(String[] args) {
      System.out.println(Character.isDigit('7'));
      System.out.println(Character.isLetter('๊ฐ€'));
   }
}

 

 

 


 

๋Œ“๊ธ€