I'm starting my studies with Java now and would like to know how to do an infinite count I'm having difficulties, since I know that in Python it would be something like:
a = 0
while True:
a = a + 1
print(a)
I'm starting my studies with Java now and would like to know how to do an infinite count I'm having difficulties, since I know that in Python it would be something like:
a = 0
while True:
a = a + 1
print(a)
Whatever the language, your "infinity" is relative to the maximum size that the type of data you use supports or, ultimately, the available memory of your machine. This means that infinity of a Integer
is well (BEM) less than the infinity of a BigInteger
, for example. In other words, infinity is by itself a conceptual mistake.
That's right, a form of loop "infinite", the largest you'll get in Java until you fill up the memory of your device:
BigInteger infinito = BigInteger.ZERO;
for(;;) {
infinito = infinito.add(BigInteger.ONE);
System.out.println(infinito);
}