There is a recursive code for calculating a continued fraction:
import java.math.*; import java.io.*; import java.util.*; public class ContinuedFraction { public static void main(String args[ ]) { double z= cep(1071/462); System.out.println(z); } public static double cep(double drobchast) { if((1/drobchast) - (Math.ceil(1/drobchast) - 1) == 0) { return 1/drobchast; } double celchast = Math.ceil(1/drobchast) - 1; drobchast = 1/(celchast + (1/drobchast)); return cep(drobchast); } } I will try to explain my logic: condition(1/drobchast) - (Math.ceil(1/drobchast) - 1) == 0 assumes that if you turn the shot and it does not have a residue (for example, we turn 1/7 and get 7), then we have reached the end point .
Otherwise, you need to transfer the unit divided by the integer part cut off from the fraction, plus the unit divided by the inverted fraction.
Now when I run my code, a stack error is displayed.