Skip to main content
added 191 characters in body
Source Link
ublec
  • 162
  • 2
  • 16

I once decided to add two chars together, and it gave me a number. Here's the code:

class Main {
  public static void main(String[] args) {
    System.out.println('a'+'b');
  }
}

Output: 195.

I've searched in a lot of places, but I still couldn't figure out why a char + char = int. Can someone explain this to me?

NOTE: THIS IS NOT A DUPLICATE!! The other question is asking the data type of an added char. This question asks why this happens. Those are DIFFERENT QUESTIONS WITH DIFFERENT ANSWERS!

I once decided to add two chars together, and it gave me a number. Here's the code:

class Main {
  public static void main(String[] args) {
    System.out.println('a'+'b');
  }
}

Output: 195.

I've searched in a lot of places, but I still couldn't figure out why a char + char = int. Can someone explain this to me?

I once decided to add two chars together, and it gave me a number. Here's the code:

class Main {
  public static void main(String[] args) {
    System.out.println('a'+'b');
  }
}

Output: 195.

I've searched in a lot of places, but I still couldn't figure out why a char + char = int. Can someone explain this to me?

NOTE: THIS IS NOT A DUPLICATE!! The other question is asking the data type of an added char. This question asks why this happens. Those are DIFFERENT QUESTIONS WITH DIFFERENT ANSWERS!

Post Closed as "Duplicate" by Mark Rotteveel java
Source Link
ublec
  • 162
  • 2
  • 16

Why do I get a number when I add chars?

I once decided to add two chars together, and it gave me a number. Here's the code:

class Main {
  public static void main(String[] args) {
    System.out.println('a'+'b');
  }
}

Output: 195.

I've searched in a lot of places, but I still couldn't figure out why a char + char = int. Can someone explain this to me?