I am new to java programming language. Why there are different output in this code?Can explain the problem to me?Thank you very much. public class Collatz {
public static void main(String[]arguments)
{ int max=0;
int real=0;
int a=0;
for (int i=2;i<1000000;i++)
{
real=i;
int count=1;
while(real>1)
{
if(real%2==0)
{
real=real/2;
}
else
{
real=3*real+1;
}
count++;
}
if(count>max){max=count;a=i;}
}
System.out.println(a+"&"+max);}
Output is 910107&476 public class Collatz {
public static void main(String[]arguments)
{ long max=0;
long real=0;
long a=0;
for (int i=2;i<1000000;i++)
{
real=i;
int count=1;
while(real>1)
{
if(real%2==0)
{
real=real/2;
}
else
{
real=3*real+1;
}
count++;
}
if(count>max){max=count;a=i;}
}
System.out.println(a+"&"+max);}
Output is 837799&525 Can tell me what is the problem?Thank you.