Character 클래스의 isDigit(int codePoint) 메소드는 일반적으로 주어진 문자가 숫자인지 여부를 판별합니다. 일반적으로 getType(codePoint)에 의해 제공된 일반 범주가 DECIMAL_DIGIT_NUMBER인 경우 문자는 숫자로 간주됩니다.
통사론
public static boolean isDigit(int codePoint)
매개변수
위의 방법에는 하나의 매개변수만 필요합니다.
C의 행렬 곱셈
a.)테스트해야 하는 유니코드 문자인 codePoint입니다.
반환 값
isDigit(int codePoint) 메소드는 주어진(또는 지정된) 문자가 숫자인 경우 부울 값, 즉 true를 반환합니다. 그렇지 않으면 메서드는 false를 반환합니다.
실시예 1
public class JavaCharacaterisDigitintcodePointExample1 { public static void main(String[] args) { // Initialize the codePoints. int codepoint1 = 55; int codepoint2 = 32; int codepoint3 = 121; int codepoint4 = 49; int codepoint5 = 200; // Check whether a particular codePoint is a digit or not. boolean check1 = Character.isDigit(codepoint1); boolean check2 = Character.isDigit(codepoint2); boolean check3 = Character.isDigit(codepoint3); boolean check4 = Character.isDigit(codepoint4); boolean check5 = Character.isDigit(codepoint5); // Print the result. if(check1){ System.out.print('The codePoint ''+codepoint1+'' is a digit. '); } else{ System.out.print('The codePoint ''+codepoint1+'' is not a digit. '); } if(check2){ System.out.print('The codePoint ''+codepoint2+'' is a digit. '); } else{ System.out.print('The codePoint ''+codepoint2+'' is not a digit. '); } if(check3){ System.out.print('The codePoint ''+codepoint3+'' is a digit. '); } else{ System.out.print('The codePoint ''+codepoint3+'' is not a digit. '); } if(check4){ System.out.print('The codePoint ''+codepoint4+'' is a digit. '); } else{ System.out.print('The codePoint ''+codepoint4+'' is not a digit. '); } if(check5){ System.out.print('The codePoint ''+codepoint5+'' is a digit. '); } else{ System.out.print('The codePoint ''+codepoint5+'' is not a digit. '); } } }지금 테스트해보세요
산출:
The codePoint '55' is a digit. The codePoint '32' is not a digit. The codePoint '121' is not a digit. The codePoint '49' is a digit. The codePoint '200' is not a digit.
실시예 2
public class JavaCharacaterisDigitintcodePointExample2 { public static void main(String[] args) { // Create four int primitives obj1, obj2, obj3 and obj4. int obj1, obj2, obj3, obj4; // Assign the values to obj1, obj2, obj3 and obj4. obj1 = 0x06f8; obj2 = 0x0432; obj3 = 0x50; obj4 = 0x0c12; // Create four boolean primitives b1, b2, b3 and b4. boolean b1, b2, b3, b4; // Assign the isDigit method b1 = Character.isDigit(obj1); b2 = Character.isDigit(obj2); b3 = Character.isDigit(obj3); b4 = Character.isDigit(obj4); String str1 = 'The first object represents a digit : ' + b1; String str2 = 'The first object represents a digit : ' + b2; String str3 = 'The first object represents a digit : ' + b3; String str4 = 'The first object represents a digit : ' + b4; // Print the values of b1, b2, b3 and b4. System.out.println( str1 ); System.out.println( str2 ); System.out.println( str3 ); System.out.println( str4 ); } }지금 테스트해보세요
산출:
C# 날짜 시간
The first object represents a digit : true The first object represents a digit : false The first object represents a digit : false The first object represents a digit : false
Character 클래스의 isDigit(char ch) 메소드는 일반적으로 주어진 문자가 숫자인지 여부를 판별합니다.
일반적으로 Character.getType(ch)에 의해 제공된 일반 범주가 DECIMAL_DIGIT_NUMBER인 경우 문자는 숫자로 간주됩니다.
참고: 위의 방법은 보조 문자를 처리하는 데 사용할 수 없습니다. 모든 보조 문자를 포함하여 모든 유니코드 문자를 지원하려면 isdigit(int) 메서드를 사용할 수 있습니다.
통사론
public static boolean isDefined(char ch)
매개변수
위의 방법에는 하나의 매개변수만 필요합니다.
... 자바에서a.)테스트가 필요한 캐릭터입니다.
반환 값
isDigit(char ch) 메소드는 부울 값을 반환합니다. 즉, 주어진(또는 지정된) 문자가 숫자이면 true입니다. 그렇지 않으면 메서드는 false를 반환합니다.
실시예 3
public class JavaCharacterisDigitExample3 { public static void main(String[] args) { // Create three char primitives: obj1, obj2, and obj3. char obj1, obj2, obj3; // Assign the values to obj1, obj2 and obj3 respectively. obj1 = ' '; obj2 = '4'; obj3 = '8'; // Create three boolean primitives b1, b2 and b3. boolean b1, b2,b3; //Assign isDigit results of obj1, obj2 and obj3 to b1, b2, and b3 respectively. b1 = Character.isDigit(obj1); b2 = Character.isDigit(obj2); b3 = Character.isDigit(obj3); String str1 = 'The digit '' + obj1 +'' is:'+b1; String str2 = 'The digit '' + obj2 +'' is:'+b2; String str3 = 'The digit '' + obj3 +'' is:'+b3; // Print the values of b1, b2 and b3. System.out.println( str1 ); System.out.println( str2 ); System.out.println( str3 ); } }지금 테스트해보세요
산출:
The digit ' ' is:false The digit '4' is:true The digit '8' is:true
실시예 4
import java.util.Scanner; public class JavaCharacterisDigitExample4 { public static void main(String[] args) { // Ask the user to enter the first character. System.out.print('Enter the first character:'); // Use scanner to get the user input. Scanner s1 = new Scanner(System.in); char value1 = s1.nextLine().toCharArray()[0]; // Check whether the input is digit or not. boolean check1 = Character.isDigit(value1); // Print the result if(check1){ System.out.print('The character ''+value1+'' is a digit. '); } else{ System.out.print('The character ''+value1+'' is not a digit. '); } // Ask the user to enter the second character. System.out.print('Enter the first character:'); // Use scanner to get the user input. Scanner s2 = new Scanner(System.in); char value2 = s2.nextLine().toCharArray()[0]; // Check whether the input is digit or not. boolean check2 = Character.isDigit(value2); // Print the result. if(check2){ System.out.print('The character ''+value2+'' is a digit. '); } else{ System.out.print('The character ''+value2+'' is not a digit. '); } } }지금 테스트해보세요
산출:
Enter the first character: & The character '&' is not a digit. Enter the first character: 3 The character '3' is a digit.
실시예 5
public class JavaCharacterisDigitExample5 { public static void main(String[] args) { // Create four char primitives: obj1, obj2, obj3 and obj4. char obj1, obj2, obj3, obj4; // Assign the values to obj1, obj2, obj3 and obj4 respectively. obj1 = 'A'; obj2 = '3'; obj3 = 'b'; obj4 = '6'; // Create four boolean primitives b1, b2, b3, and b4. boolean b1, b2,b3,b4; // Assign isDigit results of obj1, obj2, obj3, and obj4 to b1, b2 and b3 respectively. b1 = Character.isDigit(obj1); b2 = Character.isDigit(obj2); b3 = Character.isDigit(obj3); b4 = Character.isDigit(obj4); String str1 = 'The digit '' + obj1 +'' is:'+b1; String str2 = 'The digit '' + obj2 +'' is:'+b2; String str3 = 'The digit '' + obj3 +'' is:'+b3; String str4 = 'The digit '' + obj4 +'' is:'+b4; // Print the values of b1, b2, b3 and b4. System.out.println( str1 ); System.out.println( str2 ); System.out.println( str3 ); System.out.println( str4 ); } }지금 테스트해보세요
산출:
The digit 'A' is:false The digit '3' is:true The digit 'b' is:false The digit '6' is:true