0

Code

    public class main {
    
        public static void main(String[] args) {
            System.out.println(1101101101*10);
        }
    
    }

OUTPUT

-1873890878

calci

I do the same thing in python it gives the output.

     Microsoft Windows [Version 10.0.19044.2251]
    (c) Microsoft Corporation. All rights reserved.

    C:\Users\pradeep>python
    Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1101101101*10
    11011011010
    

How can I solve this in java ?

Pradeep Simba
  • 282
  • 5
  • 15

2 Answers2

2

Any number written literally like 1101101101 or 10 is considered an Integer by default in java. And Integer in java represents any whole number from -2147483648 to 2147483647. your argument makes the output exceed the said range, your IDE probably raise a warning that said Numeric overflow in expression, maybe you didn't notice that.

Tan Sang
  • 320
  • 2
  • 10
1

Below code might solve your problem .

 public static void main(String[] args) {

    Long longVal = 1101101101l;
    System.out.println(longVal*10);
}