- 这个 性格getType(char-ch) 是java中的一个内置方法,返回一个值,该值指示角色的一般类别。此方法无法处理补充字符。要支持所有Unicode字符,包括补充字符,请使用getType(int)方法。
语法:
public static int getType(char ch)
参数: 该方法接受一个参数 中国 指要测试的字符的字符数据类型。
返回值: 此方法返回一个integer类型的值,该值表示角色的常规类别。
下面的程序演示了字符的使用。getType(char-ch)方法: 项目1:
import
java.lang.*;
public
class
gfg {
public
static
void
main(String[] args) {
// Create 2 character primitives ch1, ch2 and assigning values
char
c1 =
'K'
, c2 =
'%'
;
// Assign getType values of c1, c2 to int primitives int1, int2
int
int1 = Character.getType(c1);
int
int2 = Character.getType(c2);
String str1 =
"Category of "
+ c1 +
" is "
+ int1;
String str2 =
"Category of "
+ c2 +
" is "
+ int2;
System.out.println( str1 );
System.out.println( str2 );
}
}
输出:Category of K is 1 Category of % is 24
项目2:
import
java.lang.*;
public
class
gfg {
public
static
void
main(String[] args) {
// Create 2 character primitives ch1, ch2 and assigning values
char
c1 =
'T'
, c2 =
'^'
;
// Assign getType values of c1, c2 to inyt primitives int1, int2
int
int1 = Character.getType(c1);
int
int2 = Character.getType(c2);
String str1 =
"Category of "
+ c1 +
" is "
+ int1;
String str2 =
"Category of "
+ c2 +
" is "
+ int2;
System.out.println(str1);
System.out.println(str2);
}
}
输出:Category of T is 1 Category of ^ is 27
- 这个 JAVAlang.字符getType(int代码点) 与之前的方法在所有方面都类似,该方法可以处理补充字符。
语法:
public static int getType(int codePoint)
参数: 该方法只接受一个参数 代码点 整数数据类型,并指要测试的字符(Unicode代码点)。
返回值: 此方法返回一个int类型的值,该值表示角色的常规类别。
以下程序演示了上述方法: 项目1:
// Java program to demonstrate
// the above method
import
java.lang.*;
public
class
gfg {
public
static
void
main(String[] args) {
// int primitives c1, c2
int
c1 =
0x0037
, c2 =
0x016f
;
// Assign getType values of c1, c2 to int primitives int1, int2
int
int1 = Character.getType(c1);
int
int2 = Character.getType(c2);
// Print int1, int2 values
System.out.println(
"Category of c1 is "
+ int1);
System.out.println(
"Category of c1 is "
+ int2);
}
}
输出:Category of c1 is 9 Category of c1 is 2
项目2:
// Java program to demonstrate
// the above method
import
java.lang.*;
public
class
gfg {
public
static
void
main(String[] args) {
// int primitives c1, c2
int
c1 =
0x0135
, c2 =
0x015f
;
// Assign getType values of c1, c2 to int primitives int1, int2
int
int1 = Character.getType(c1);
int
int2 = Character.getType(c2);
// Print int1, int2 values
System.out.println(
"Category of c1 is "
+ int1);
System.out.println(
"Category of c1 is "
+ int2);
}
}
输出:Category of c1 is 2 Category of c1 is 2
参考: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#getType(字符)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END