玩滑板的皮带 · Any demo converting a ...· 2 月前 · |
怕老婆的水龙头 · 【上海热线】交大成立BIM研究中心 ...· 3 月前 · |
爱吹牛的水煮肉 · Go 每日一库之 ...· 4 月前 · |
失恋的橡皮擦 · 关于动态链接库(dynamic ...· 6 月前 · |
完美的脸盆 · SiteMinder: The ...· 1 年前 · |
Apart from the above mentioned ranges, many other character ranges contain digits as well.
Syntax:
Parameter: This method accepts character parameter ch as an argument, which is to be tested.
Return value: This method returns a boolean value. It returns True if ch is digit, else False.
Note: This method cannot handle supplementary characters . To support all Unicode characters, including supplementary characters, use the isDigit(int) method.
Below programs illustrate the above method:
Program 1:
// Function to check if is digit
// is found or not
for
(
int
i =
0
; i < s.length(); i++) {
if
(Character.isDigit(
s.charAt(i))
==
true
) {
// return position of digit
return
i +
1
;
// return 0 if digit not present
return
0
;
public
static
void
main(String[] args)
// Array of strings
String[] arr = {
"ABC4DEF"
,
"QWERTY"
};
// To store the position of digit
int
index =
0
;
// Traverse the array arr[] to find digit
// within it's elements
for
(String x : arr) {
index = search_digit(x);
if
(index !=
0
) {
System.out.println(
"Digit found at : "
+ (index)
+
"th position."
);
else
{
System.out.println(
"Digit not present."
);
Apart from the above mentioned ranges, many other character ranges contain digits as well.
Syntax:
Parameter: This method accepts unicode character parameter codePoint of integer type as an argument, which is to be tested.
Return value: This method returns a boolean value. It returns True if the specified character is digit, else it returns False.
Below programs illustrate the above method:
Program 1:
// This program demonstrates the use of
// isDigit(int codePoint) method of Character class.
import
java.util.*;
public
class
GFG {
public
static
void
main(String[] args)
// create codePoints
int
cp1 =
57
;
int
cp2 =
84
;
// Check whether the codePoints
// are digit or not.
System.out.println(
"The codePoint cp1 is a digit -> "
+ Character.isDigit(cp1));
System.out.println(
"The codePoint cp2 is a digit -> "
+ Character.isDigit(cp2));
// This program demonstrates the use of
// isDigit(int codePoint) method of
// Character class.
import
java.util.*;
public
class
Main {
public
static
void
main(String[] args)
// create codePoints
int
cp1 =
0x50
;
int
cp2 =
0x06f8
;
// Check whether the codePoints
// are digit or not.
System.out.println(
"The codePoint cp1 is a digit -> "
+ Character.isDigit(cp1));
System.out.println(
"The codePoint cp2 is a digit -> "
+ Character.isDigit(cp2));