Ascii characters are actually numbers. And 0 .. 9
digits are numbers starting from decimal 48 (0x30 hexadecimal).
'0' is 48 '1' is 49 ... '9' is 57
So to get the value of any character digit, you can just remove the ‘0’, ie 48.
'1' - '0' => 1 49 - 48 => 1
If you don’t remove ‘0’ (48) the total sum will be over by 48 * numberOfDigits
.
See an ascii table to locate digits in it.
Note that '0'
is the character 0
, not the string "0"
containing the character '0'
.
Related Posts:
- How to format strings in Java
- What exactly is Apache Camel?
- What is an instance variable in Java?
- How does the Java ‘for each’ loop work?
- How does the Java ‘for each’ loop work?
- What does “Could not find or load main class” mean?
- How do I create a file and write to it?
- When to use LinkedList over ArrayList in Java?
- How to convert a char to a String?
- How do you create a dictionary in Java? [closed]
- How do I declare and initialize an array in Java?
- Convert list to array in Java [duplicate]
- How can I use pointers in Java?
- How do I generate random integers within a specific range in Java?
- “Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0″ with ArrayList?
- Raising a number to a power in Java
- Running JAR file on Windows 10
- How do I limit the number of decimals printed for a double?
- Unfortunately MyApp has stopped. How can I solve this?
- exception in thread ‘main’ java.lang.NoClassDefFoundError:
- java.io.FileNotFoundException: the system cannot find the file specified
- How to parse this string in Java?
- How to match “any character” in regular expression?
- Double array initialization in Java
- I want to declare an empty array in java and then I want do update it but the code is not working
- Convert .class to .java
- What does Scanner input = new Scanner(System.in) actually mean?
- Why is there no Constant feature in Java?
- Error creating bean with name ‘entityManagerFactory’ defined in class path resource : Invocation of init method failed
- Printing out a linked list using toString
- Using @RequestLine with Feign
- What is the best/simplest way to read in an XML file in Java application?
- Received fatal alert: handshake_failure through SSLHandshakeException
- DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704
- Why would a “java.net.ConnectException: Connection timed out” exception occur when URL is up?
- HashSet vs. ArrayList
- FIFO based Queue implementations?
- How to import a .cer certificate into a java keystore?
- How to get the current working directory in Java?
- What is a safe way to create a Temp file in Java?
- Android java.lang.IllegalStateException: Could not execute method of the activity
- Java error: Comparison method violates its general contract
- “Cannot create generic array of ..” – how to create an Array of Map
? - Java and Windows – error: illegal escape character
- How should I copy Strings in Java?
- Bank Account Java Program
- List of all special characters that need to be escaped in a regex
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
- java.lang.ArithmeticException: / by zero
- Eclipse error, “The selection cannot be launched, and there are no recent launches”
- STS launch error – Java was started but returned exit code=13
- RecyclerView onClick
- Java, Shifting Elements in an Array
- error: bad operand types for binary operator ‘&&’
- Exception in thread “main” java.lang.ArithmeticException: / by zero
- Failed to load the JNI shared Library (JDK)
- “com.jcraft.jsch.JSchException: Auth fail” with working passwords
- java.util.NoSuchElementException – Scanner reading user input
- How would I use a while loop to keep requesting user input
- Array Required, but java.lang.String found
- Eclipse java debugging: source not found
- IntelliJ – Can’t start – “JAVA_HOME does not point to a valid JVM installation”
- difference between equals() and hashCode()
- Adding days to a date in Java
- The C# Shorthand getters and setters
- What’s the reason I can’t create generic array types in Java?
- How to pass an object from one activity to another on Android
- Finding the size of a char array in Java
- Android For loop
- Java project in Eclipse: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
- Replace a character at a specific index in a string?
- Error array dimension missing
- How to detect EOF in Java?
- fixing errors on a program to call methods in java
- How to Set the Background Color of a JButton on the Mac OS
- How to easily convert a BufferedReader to a String?
- How can I calculate a time difference in Java?
- Detecting a long press with Android
- How to increase the size of an array in Java?
- Cannot invoke toString() on the primitive type int
- Creating a Calendar using javafx
- A tool for calculating the big-O time complexity of Java code? [closed]
- How to print binary tree diagram in Java?
- Must qualify the allocation with an enclosing instance of type GeoLocation
- Unknown version of Tomcat was specified in Eclipse
- How to compare character ignoring case in primitive types
- intellij idea – Error: java: invalid source release 1.9
- How fix Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
- Is it okay to throw NullPointerException programmatically?
- Android: how to create Switch case from this?
- Read next word in java
- Convert float to double without losing precision
- Exception in thread “AWT-EventQueue-0” java.lang.OutOfMemoryError: Java heap space
- How do the post increment (i++) and pre increment (++i) operators work in Java?
- Manually throw an exception
- Spring boot: Unable to start embedded Tomcat servlet container
- How does paintComponent work?
- toring and Retrieving ArrayList values from hashmap
- Could not find or load main class with a Jar File
- “uses unchecked or unsafe operations” [duplicate]