View Code of Problem 42


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
	public static void main(String args[]) throws IOException 
	{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		while(true)
		{
			String ll = reader.readLine();
			//
			String a = "";
			String b = "";
			String c = "";
			int i = 0;
			for(;i<ll.length();i++)
			{
				char aa = ll.charAt(i);
				if (aa == ' ')
				{
					break;
				}
				else
				{
					a = a + aa;
				}
				
			}
			i++;
			for(;i<ll.length();i++)
			{
				char aa = ll.charAt(i);
				if (aa == ' ')
				{
					break;
					
				}
				else
				{
					b = b + aa;
				}
			}
			i++;
			for(;i<ll.length();i++)
			{
				char aa = ll.charAt(i);
				if (aa == '\n')
				{
					break;
				}
				else
				{
					c = c + aa;
				}
			}
//			System.out.println(a);
//			System.out.println(b);
//			System.out.println(c);
			float a1 = Float.parseFloat(a);
			float b1 = Float.parseFloat(b);
			float c1 = Float.parseFloat(c);
			float x1 = (float) ((-b1+Math.sqrt(b1*b1-4*a1*c1))/(2*a1));
			float x2 = (float)((-b1-Math.sqrt(b1*b1-4*a1*c1))/(2*a1));
			if(x1 < x2)
			{
				float temp = x2 ;
				x2 = x1;
				x1 = temp;
			}
			System.out.println(String.format("%.2f", x1)+' '+String.format("%.2f", x2));
			
			
			
		}
		
		
		
	}
}
			
		
		
		
		
	

Double click to view unformatted code.


Back to problem 42