The ASCII table is arranged so that the value of the character '9'
is nine greater than the value of '0'
; the value of the character '8'
is eight greater than the value of '0'
; and so on.
So you can get the int value of a decimal digit char by subtracting '0'
.
char x = '9'; int y = x - '0'; // gives the int value 9
Related Posts:
- How do I convert a String to an int in Java?
- How to convert a char to a String?
- Convert int to char in java
- Java – Convert integer to string [duplicate]
- How to convert/parse from String to char in java?
- Convert String to double in Java
- “Char cannot be dereferenced” error
- “Char cannot be dereferenced” error
- “int cannot be dereferenced” in Java
- Create ArrayList from array
- Java JDK – possible lossy conversion from double to int
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- How do I limit the number of decimals printed for a double?
- How do I limit the number of decimals printed for a double?
- Illegal Escape Character “\”
- How to check if an int is a null
- Convert an integer to an array of characters : java
- How do I apply the for-each loop to every character in a String?
- Understanding the difference between null and ‘\u000’ in Java
- Understanding the difference between null and ‘\u000’ in Java
- How to check whether a int is not null or empty?
- Converting Hexadecimal String to Decimal Integer
- What is the difference between Integer and int in Java?
- Java, Simplified check if int array contains int
- JAVA Variable declaration not allowed here
- Unclosed Character Literal error
- Java Array Sort descending?
- Determine if a String is an Integer in Java [duplicate]
- Convert boolean to int in Java
- Convert double to Int, rounded down
- Converting from byte to int in Java
- How to Convert Int to Unsigned Byte and Back
- Java – Change int to ascii
- Java Not Greater than Or Equal to Operator for Char Type
- Conversion from Long to Double in Java
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- What is a StackOverflowError?
- How to uninstall Eclipse?
- Change date format in a Java string
- Converting String to “Character” array in Java
- Java – What does “\n” mean? [duplicate]
- must declare a named package eclipse because this compilation unit is associated to the named module
- Exception in thread “main” java.lang.StackOverflowError
- Best way to convert an ArrayList to a string
- Compiled vs. Interpreted Languages
- How to round up to the next integer?
- Spring @PropertySources value not overriding
- Array ArrayList python equivalent
- Java ArrayList copy
- Getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception
- Explain the use of a bit vector for determining if all characters are unique
- What does the following Oracle error mean: invalid column index
- Sorting HashMap by values
- Will Arrays.sort() increase time complexity and space time complexity?
- Maven: Failed to read artifact descriptor
- The system cannot find the file specified in java
- Java Generate Random Number Between Two Given Values
- Causes of getting a java.lang.VerifyError
- “Unmappable character for encoding UTF-8” error
- UnsatisfiedDependencyException: Error creating bean with name
- Random shuffling of an array
- How to convert int[] to Integer[] in Java?
- Why am I getting a “; expected” error?
- How/where to download openjdk/openjre for windows [duplicate]
- copy a 2d array in java
- java.lang.ClassNotFoundException: org.sqlite.JDBC error in Sample.java program from xerial
- How can I truncate a double to only two decimal places in Java?
- Cannot resolve symbol “Intent”
- What is the default initialization of an array in Java?
- java sort using anonymous class
- How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error
- channel 3: open failed: connect failed: Connection refused
- Java Currency Number format
- How to Set JPanel’s Width and Height?
- addMouseListener for a JPanel
- What is the difference between an Abstract Data Type(ADT) and a Data Structure?
- What is the jasperrepots-fonts jar for and how to use it?
- Does Java have an StringStream equivalent?
- Difference between String replace() and replaceAll()
- How do I get the size of a java.sql.ResultSet?
- Java: How to set Precision for double value?
- Any way to declare an array in-line?
- java.io.StreamCorruptedException: invalid stream header: 54657374
- How to return nothing from a function that returns value?
- Java simple code: java.net.SocketException: Unexpected end of file from server
- What is the best Java email address validation method?
- Set Date in a single line
- why android studio show error of “Missing constraints in constraintlayout”?
- Change the size of a JTextField inside a JBorderLayout
- java.lang.ArrayIndexOutOfBoundsException: 0
- What’s wrong with overridable method calls in constructors?
- what is the difference between doGet() and doPost() in term of the flow?
- java.util.ConcurrentModificationException with iterator
- How to read file from relative path in Java project? java.io.File cannot find the path specified
- How can I view and edit specific aspects of playerdata from my Minecraft server?
- String index out of bounds exception java
- Javadoc @author tag good practices
- A fatal error has been detected by the Java Runtime Environment: SIGSEGV, libjvm
- java.lang.IllegalStateException: Failed to introspect Class
- ShoppingCart.Java Program Assignment