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 line = reader.readLine();
			//
			String a = "";
			String b ="";
		    String c ="";
		    int i = 0;
		    for(; i < line.length(); i++ )
		    {
		    	char temp = line.charAt(i);
		    	if (temp == ' ')
		    	
		    	{
		    		break;
		    	}
		    	else 
		    	{
		    		a = a + temp;
		    	}
		    
		    }
		    i++;
		    for(; i<line.length();i++)
		    {
		    	char temp = line.charAt(i);
		    	if (temp == ' ')
		    	{
		    		break;
		    	
		    		
		    	}
		    	else
		    	{
		    		b = b + temp;
		    	}
		    }
		    i++;
		    for(; i < line.length();i++)
		    {
		    	char temp = line.charAt(i);
		    	if (temp == '\n')
		    	{
		    		break;
		    	}
		    	else
		    	{
		    		c = c + temp;
		    	}
		    }
//		    System.out.println(a);
//		    System.out.println(b);
//		    System.out.println(c);
//		    Float.parseFloat(a);
		    float aa = Float.parseFloat(a);
		    float bb = Float.parseFloat(b);
		    float cc = Float.parseFloat(c);
		    float x1 =(-bb+(float)Math.sqrt(Math.abs(bb*bb-4*aa*cc)))/(2*aa);
		    float x2 = (-bb-(float)Math.sqrt(Math.abs(bb*bb-4*aa*cc)))/(2*aa);
		    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