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

  • SEARCH
  • Home
  • 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 8220897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:42:36+00:00 2026-06-07T13:42:36+00:00

When I run the following code it doesn’t give me the output that I’ve

  • 0

When I run the following code it doesn’t give me the output that I’ve been excepted. Consider the following code-snippet:

public class T
{
    public static void main(String arg[])
    {
        char a='3';
        System.out.println(a+a);
    }
}

The output here is : 102

Could please anybody explain that to me ?

  • 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-07T13:42:39+00:00Added an answer on June 7, 2026 at 1:42 pm

    The + operator applies an implicit type cast which converts the two characters into their numerical ASCII representation which is 51.

    So the expression

    '3'+'3'
    

    can also be seen as

    51 + 51
    

    which is 102.

    I assume what you want to have is the result "33" which is not a char any more but a string. To achieve this you can for example simply implicitly convert the result of the expression into a string:

    char c = '3';
    string s = "" + c + c;
    

    Another possibility would be to facilitate the StringBuilder class:

    char c = '3';
    String s = new StringBuilder().append(c).append(c).toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run the following code from command line: public class MemoryTest { public static
The following code doesn't appear to run when executed by code: Stored procedure snippet:
I run the following code snippet. Public Shared Sub DisplayDnsConfiguration() Dim adapters As NetworkInterface()
I have the following sample code which doesn't seem to want to run. import
When I run the following code I get B as expected: class A {
I have the following code which doesn't run properly. char dec_number[300]; dec_number[0]='\0'; //some code
If you run the following code, you will see that the URI has a
Website has the following code: <ul class=left> <li><div id=run class=button><div class=inner>Run</div></div></li> </ul> And this
Consider the following code in a class called Worker FileSystemWatcher watcher = new FileSystemWatcher();
W/hen i run the following code snippet #!/bin/bash if [ foo = foo ];

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.