Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8448813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:31:52+00:00 2026-06-10T10:31:52+00:00

When testing this (with the below code), the ASCII value for char ‘a’ is

  • 0

When testing this (with the below code), the ASCII value for char 'a' is 10, and the ASCII value for char 'b' is 11. However, when concatenating char 'a' and char 'b', the result is 195.

There must be an error in my logic and/or understanding here… I do understand that chars cannot be concatenated as a String, but what would the ASCII int value of 195 then represent?

And what would be the usage of such a result?


Here is my code:

public class Concatenated
{
    public static void main(String[] args)
    {
        char char1 = 'a';
        char char2 = 'b';

        String str1 = "abc";

        String result = "";
        int intResult = 0;
        Concatenated obj = new Concatenated();

        // calling methods here
        intResult = obj.getASCII(char1);
        System.out.println("The ASCII value of char \"" + char1 + "\" is: " + intResult + ".");

        intResult = obj.getASCII(char2);
        System.out.println("The ASCII value of char \"" + char2 + "\" is: " + intResult + ".");

        result = obj.concatChars(char1, char2);
        System.out.println(char1 + " + " + char2 + " = " + result + ".");

        result = obj.concatCharString(char1, str1);
        System.out.println("The char \"" + char1 + "\" + the String \"" + str1 + "\" = " + result + ".");
    } // end of main method

    public int getASCII(char testChar)
    {
        int ans = Character.getNumericValue(testChar);

        return ans;
    } // end of method getASCII

    public String concatChars(char firstChar, char secondChar)
    {
        String ans = "";
        ans += firstChar + secondChar; // "+=" is executed last

        return ans; // returns ASCII value
    } // end of method concatChars

    public String concatCharString(char firstChar, String str)
    {
        String ans = "";
        ans += firstChar + str;

        return ans;
    } // end of method concatCharString
} // end of class Concatenated


…the result printed to screen is as follows:

The ASCII value of char "a" is: 10.
The ASCII value of char "b" is: 11.
a + b = 195.
The char "a" + the String "abc" = aabc.


—  EDIT :   —

As @Marko Topolnik has pointed out below, the method getASCII should be changed to this to return the correct ASCII value (and not the UNICODE value):

public int getASCII(char testChar)
{
    // int ans = Character.getNumericValue(testChar); ...returns a UNICODE value!
    int ans = testChar;

    return ans;
} // end of method getASCII

I haven’t changed the above code to reflect this, for posterity sake.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:31:54+00:00Added an answer on June 10, 2026 at 10:31 am

    Character.getNumericValue() returns the int value that the specified Unicode character represents.
    According to the getNumericValue() Javadocs: “The A tp Z letters both in uppercase and lowercase have numeric values from 10 through 35. This is independent of the Unicode specification, which does not assign numeric values to these char values.”

    However, when you add them in the concatChars() method, the 2 values that are added are the ASCII values (97 + 98).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
See code below: I want Page 1 to alert #testing... This works in C
I get this error, while I'm testing the code below: You have an error
IOW, is there a standard way of testing for this, a la: if (!
I'm trying to insert UL on every 20th sub category label. This code below
The button doesn't show in this layout(code below),image and textview are shown. I tried
At this point I'm stumped. The below embed code causes Object Required errors every
I have this extremely strange behavior coming : In the below code: If I
I was just testing this download script below. The downloading works fine but the
I'm testing this out in LINQPad with the CRM plugin. What should my query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.