A
A
Alexander2018-07-08 21:37:31
Java
Alexander, 2018-07-08 21:37:31

Why can't java count?

for (int x = 1; x<=1500000000; x*=10){
            System.out.println(x);
        }

Outputs :
1
10
100
1000
10000
100000
1000000
10000000
100000000
1000000000
1410065408
1215752192
-727379968
13161344912
276447232
-15304

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Decadal, 2018-07-08
@AleksandrB

in java, the int type holds 32 bits. This is from -2147483648 to 2147483647

A
Alexander, 2018-07-08
@alexr64

Because int is over.

M
Maxim Moseychuk, 2018-07-08
@fshp

Because the size of int is finite. Do you want endless? Use BigInteger. And read about additional code and overflow. This is a school course in computer science.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question