About 41,400 results
Open links in new tab
  1. java - Adding char and int - Stack Overflow

    Chars in Java can be promoted to int, so if you ask to add an int like 1 to a char like '1', alias 49, the more narrow type char is promoted to int, getting 49, + 1 => 50. Note that every non-digit char can be added the same way: 'char' is really just a two-byte unsigned integer.

  2. How do I add an integer to a char in Java? - Stack Overflow

    Nov 29, 2012 · In Java, char and int are compatible types so just add them with + operator. char c = 'c'; int x = 10; c + x results in an integer, so you need an explicit casting to assign it to your character varaible back.

  3. In Java, is the result of the addition of two chars an int or a char?

    Dec 31, 2011 · The result of adding Java chars, shorts, or bytes is an int: Java Language Specification on Binary Numeric Promotion: If any of the operands is of a reference type, unboxing conversion (§5.1.8) is performed. Then: If either operand is of type double, the other is converted to double.

  4. Java Program to Convert Char to Int - GeeksforGeeks

    Apr 23, 2025 · It can convert int, char, long, boolean, float, double, object, and char array to String, which can be converted to an int value by using the Integer.parseInt() method. The program below illustrates the use of the valueOf() method.

  5. Convert Between int and char in Java - Baeldung

    Jan 16, 2024 · Learn how characters are internally represented in Java and how we can convert an int to a char and back.

  6. What Data Type Is the Result of Adding Two Characters in Java: int

    In Java, adding two characters results in an integer type due to implicit type promotion. This process occurs because char types are treated as numeric values in arithmetic expressions.

  7. Convert char to int (Characters to Integers) - GeeksforGeeks

    Mar 26, 2024 · Compute the character to integer value by subtracting the code of '0' from the character code. Converting characters to integers is a common operation in programming, especially in languages like C, C++, Java, and Python. Here are some applications of converting characters to integers:

  8. Convert Char to Int in Java with examples - CodeGym

    Aug 19, 2023 · There is a very simple way to convert a character to an integer. To do this, simply subtract the ASCII value of the character "0" from the character. For example, to get int 7 from character "7": int intValue = '7'-' 0 '; Note, that this works for getting int values exclusively for integer characters!

  9. java - Adding and subtracting chars, why does this work ... - Stack ...

    How is possible to add/subtract chars from integers and what's the meaning behind it? From the Docs. The char data type is a single 16-bit Unicode character. A char is represented by its code point value: You can see all of the English alphabetic code points on an ASCII table.

  10. Understanding Type Conversion in Java: The 'char' Conundrum

    Feb 19, 2025 · The expression involves text.charAt(0), which retrieves a char. When you add 1 to this character, Java converts it into an int, performing a widening operation. text.charAt(0) returns a char (e.g., 'a'). Adding 1 implicates converting 'a' (97) into an int (98). The resulting int doesn't automatically narrow back to a char. This results in a ...

Refresh