- Joined
- Apr 22, 2005
- Sythe Gold
- 23
- Messages
- 7,825
Cheap imitation of SuF's version 
I don't know Java too well (but I do know C++), this is just my attempt to write something in Java using Microsoft Visual J++ 6.0, a 10-year old Java compiler that is long since deprecated and unsupported, but I have it, so I might as well use it a bit.
I don't know Java too well (but I do know C++), this is just my attempt to write something in Java using Microsoft Visual J++ 6.0, a 10-year old Java compiler that is long since deprecated and unsupported, but I have it, so I might as well use it a bit.
Code:
import java.lang.Math;
public class Class1
{
public static void main (String[] args)
{
double a = 0, b = 0, c = 0;
try{
a = Double.valueOf(args[0].trim()).doubleValue();
b = Double.valueOf(args[1].trim()).doubleValue();
c = Double.valueOf(args[2].trim()).doubleValue();
}
catch(NumberFormatException nfe)
{
System.out.println("NumberFormatException: " + nfe.getMessage());
return;
}
catch(ArrayIndexOutOfBoundsException oobe)
{
System.out.println("ArrayIndexOutOfBoundsException: " + oobe.getMessage());
return;
}
if(((b*b)-(4*a*c))<0)
{
System.out.println("Nonreal roots");
}
else
{
double x1 = (-b+Math.sqrt((b*b)-(4*a*c)))/(2*a);
double x2 = (-b-Math.sqrt((b*b)-(4*a*c)))/(2*a);
System.out.print("x[1] = ");
System.out.print(x1);
System.out.print("\n");
System.out.print("x[2] = ");
System.out.print(x2);
System.out.print("\n");
}
}
}






















