SuF
Legend
- Joined
- Jan 21, 2007
- Sythe Gold
- 1,234
- Messages
- 14,211
I just made this better, because I have used it like 10,000 times for math class.
. I hope you guys learn something. 
Code:
package suf;
import java.util.*;
public class QuadraticSolver
{
static boolean useAgain = true;
static Scanner s = new Scanner(System.in);
static boolean validInput = true;
public static void main(String[] args)
{
System.out.println("Welcome to SuF's Quadtratic Formula Solver!");
System.out.println("Remeber your negivtive signs!");
while (useAgain)
{
quadraticFormula();
System.out.print("Would you like to use this program again? ('Y' or 'N'):");
do
{
String answer = s.next();
validInput = true;
if (answer.equalsIgnoreCase("N"))
useAgain = false;
else if (answer.equalsIgnoreCase("Y"))
;
else
{
validInput = false;
System.out.println("Please Enter 'Y' or 'N'");
}
} while (!validInput);
}
System.out.println("\n" + "Thank you for using SuF's Quadtratic Formula Solver!");
}
public static void quadraticFormula()
{
double a = getInput("Enter A:");
double b = getInput("Enter B:");
double c = getInput("Enter C:");
double d = Math.sqrt((b * b) - (4 * a * c));
System.out.println("Answer 1: " + (-b + d) / (2 * a) + "\n" + "Answer 2: " + (-b - d) / (2 * a));
}
public static double getInput(String output)
{
while (true)
{
try
{
System.out.print(output);
return s.nextDouble();
}
catch (InputMismatchException e)
{
s.next();
}
}
}
}


