import java.io.*; public class vorrand { public static void main(String[] argumendid)throws IOException { double a=1, b=-1, c=1, d=-30; double f=0, g=0, h=0, m=0, k=0, n=0; double x1=0, x2=0, x3=0; double R=0, i=0, j=0, l=0, p=0, S=0, T=0, U=0; f=(((3*c)/a) - (((b*b)/(a*a))))/3; System.out.println("f= "+f); g=((2*((b*b*b)/(a*a*a))-(9*b*c/(a*a)) + ((27*(d/a)))))/27; System.out.println("g= "+g); h=(((g*g)/4) + ((f*f*f)/27)); System.out.println("h= "+h); if (h <= 0) { i=Math.sqrt(((g*g)/4)-h); j = Math.pow(i, (1.0/3)); k = Math.acos(- (g / (2*i))); l = (j * -1); m = Math.cos(k/3); n = (Math.sqrt (3)) * Math.sin(k/3); p = ((b/(3*a)) * -1); x1 = (2*j) * (Math.cos(k/3))-(b/(3*a)); x2 = l*(m + n) + p; x3 = l * (m - n) + p; System.out.println("i= "+i); System.out.println("j= "+j); System.out.println("k= "+k); System.out.println("l= "+l); System.out.println("m= "+m); System.out.println("n= "+n); System.out.println("p= "+p); System.out.println("x1= "+x1); System.out.println("x2= "+x2); System.out.println("x3= "+x3); } if (h>0) { f = (((3*c)/a) - ((b*b)/(a*a)))/3; System.out.println("f= "+f); g = ((2*(b*b*b)/(a*a*a)) - ((9*b*c)/(a*a)) + ((27*d)/a))/27; System.out.println("g= "+g); h = ((g*g)/4) + ((f*f*f)/27); System.out.println("h= "+h); R = -(g/2) + (Math.sqrt(h)); System.out.println("R= "+R); S = (Math.pow(R, (1.0/3))); System.out.println("S= "+S); T = -(g/2) - (Math.sqrt(h)); System.out.println("T= "+T); T=T*-1; U = (Math.pow(T, (1.0/3))); U=U*-1; System.out.println("U= "+U); x1 = (S + U) - (b/(3*a)); System.out.println("X1= "+x1); x2 = (-(S + U)/2 - (b/(3*a)) + i*(S-U)*(Math.sqrt(3))/2); System.out.println("X2= "+x2); x3 = (-(S + U)/2 - (b/(3*a)) - i*(S-U)*(Math.sqrt(3))/2); System.out.println("X3= "+x3); } if(f==0 && g==0 && h==0){ x1=(Math.pow((d/a), (1.0/3)))*-1; x2=(Math.pow((d/a), (1.0/3)))*-1; x3=(Math.pow((d/a), (1.0/3)))*-1; System.out.println("x1= "+x1); System.out.println("x2= "+x2); System.out.println("x3= "+x3); } } }