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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:59:36+00:00 2026-06-09T23:59:36+00:00

Why is the output different in these cases ? int x=20,y=10; System.out.println(printing: + x

  • 0

Why is the output different in these cases ?

int x=20,y=10;

System.out.println("printing: " + x + y); ==> printing: 2010

System.out.println("printing: " + x * y); ==> printing: 200

Why isn’t the first output 30? Is it related to operator precedence ? Like first “printing” and x are concatenated and then this resulting string and y are concatenated ? Am I correct?

  • 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-09T23:59:37+00:00Added an answer on June 9, 2026 at 11:59 pm

    Its the BODMAS Rule

    I am showing the Order of precedence below from Higher to Low:

    B  - Bracket 
    O  - Power
    DM - Division and Multiplication
    AS - Addition and Substraction
    

    This works from Left to Right if the Operators are of Same precedence

    Now

    System.out.println("printing: " + x + y);

    "printing: " : Is a String”

    "+" : Is the only overloaded operator in Java which will concatenate Number to String.
    As we have 2 “+” operator here, and x+y falls after the "printing:" + as already taken place, Its considering x and y as Strings too.

    So the output is 2010.

    System.out.println("printing: " + x * y);

    Here the

    "*": Has higher precedence than +

    So its x*y first then printing: +

    So the output is 200

    Do it like this if you want 200 as output in first case:

    System.out.println("printing: "+ (x+y));
    

    The Order of precedence of Bracket is higher to Addition.

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

Sidebar

Related Questions

Is there a way to instruct c# compiler to output source at different stages
What's the best way to output different types of responses f.ex xml, json, html,
I get different output when mocking a class once and when mocking a class
This code produces a different output in Python 2 and Python 3 . class
I've seen some questions on deciding the best OCR result given output from different
I have different php output in jQuery-based tabs. This output is formed from database
I need a method to redirect my Mac's audio output to a different computer
I'm using Hadoop 0.20.203.0. I want to output to two different files, so I'm
I would like to output debug messages in my django app at different points
Really confused why the QR output using RcppArmadillo is different than QR output from

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.