forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharToInt.java
More file actions
34 lines (30 loc) · 706 Bytes
/
CharToInt.java
File metadata and controls
34 lines (30 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.examplehub.maths;
public class CharToInt {
/**
* Convert a char ('0' - '9') to int number.
*
* @param ch the digit char.
* @return int number.
*/
public static int toInt(char ch) {
return ch - '0';
}
/**
* Convert a char ('0' - '9') to int number using build-in function.
*
* @param ch the digit char.
* @return int number.
*/
public static int toInt2(char ch) {
return Character.getNumericValue(ch);
}
/**
* Convert a char ('0' - '9') to int number using build-in function.
*
* @param ch the digit char.
* @return int number.
*/
public static int toInt3(char ch) {
return Integer.parseInt(String.valueOf(ch));
}
}