Hi,
I've got some problem in calculating recurring decimal. Whenever I try to calculate the recurring decimal of any individual fraction , I'm getting correct answer, but when I want to calculate the maximum recurring decimal of fraction, like 1/1 to 1/9, I'm getting the "1" as an answer. Here's the code for better clarification:
import java.util.*;
class RecurringDecimal
{
static ArrayList<Integer> arr=new ArrayList<Integer>();
public static void main(String[] args)
{
int position=0;
int d=1;
int r=0;
int a=1;
int big=0;
for(int div=1;div<9;div++)
{
for(;;)
{
r=d*10/div;
a=((d*10)%div)*10;
d=((d*10)%div);
position++;
if(!check(a))
{
break;
}
}
if(big<(position-1))
{
big=position-1;
}
position=0;
arr.clear();
}
System.out.println(big);
}
public static boolean check(int i){
if(arr.contains(i))
return false;
else
{
arr.add(i);
return true;
}
}
}