Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Recurring Decimal

807588Mar 27 2009 — edited Mar 27 2009
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;

	}

}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 24 2009
Added on Mar 27 2009
4 comments
161 views