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 8286833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:52:57+00:00 2026-06-08T11:52:57+00:00

When I run the following code: public class LianXi1 { public static void main(String

  • 0

When I run the following code:

public class LianXi1 
{ 
   public static void main(String args[]) 
   { 
     int a=12; 
     int b=23; 
     System.out.println("case 1"+a); //

     System.out.println("case 2"+b); //

   } 
} 

I get this result:

@ubuntu:~/mycode/test$ java LianXi1 
case 112
case 223

But I don’t understand the result, who can help?

  • 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-08T11:52:59+00:00Added an answer on June 8, 2026 at 11:52 am

    When you add a string and an integer together, it performs “String concatenation”, where it’s converting your integer into a string and sticking it on the end of the other string.

    "Case 1" + 12 
    

    … is the same as

    "Case 1" + "12"
    

    So your result will be the first string with the characters 12 stuck on after it.

    Thus: Case 112

    From the Java documentation on Strings:

    “The Java language provides special support for the string
    concatenation operator ( + ), and for conversion of other objects to
    strings. String concatenation is implemented through the StringBuffer
    class and its append method. String conversions are implemented
    through the method toString, defined by Object and inherited by all
    classes in Java. For additional information on string concatenation
    and conversion, see Gosling, Joy, and Steele, The Java Language
    Specification.”

    But be careful! Adding works left to right, so what would the follwing print?

    System.out.println(1 + 2 + "test" + 3 + 4);
    

    First, it does 1 + 2, which is equal to 3.

    Then it does 3 (the result of the last step) + "test", which causes "3test"

    Next, it does "3test" + 3, which results in "3test3".

    And finally, "3test3 + 4 is "3test34.

    As you can see, its a good idea to put parentheses around things to ensure they come out in the order you want.

    (1 + 2) + "test" + (3 + 4) would be “3test7” because the math in the parentheses has precedence.

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

Sidebar

Related Questions

I'm running the following code: public class SkipTest { public static void main(String[] args)
Consider the following code :- public class UsingWait1{ public static void main(String... aaa){ CalculateSeries
I have the following code snippet: public class A { public static void main(String[]
When I run the following code: public class Test { Test(){ System.out.println(1); } {
I run the following code from command line: public class MemoryTest { public static
I have the following code: public static void Invoke(string assemblyName, string scheduledTaskExecutorName) { ObjectHandle
Given the following code sample: public class WeirdStuff { public static int doSomething() {
I am trying to run the following simple code, public abstract class Shape{ abstract
I try to run the following code: public void Init(Url rootUrl) { var web
consider the following code: public class SynchronizedCounter extends Thread { private int c =

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.