The \b special character
Ok, I usually use JCreator for programming because it's simple... very simple, but I'm using Eclipse right now because that's all this PC has. For some reason, it won't make the \b character backspace. Here's the code, what should Ido?:
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
publicclass Quadratic
{
publicstaticvoid main(String[] args)
{
System.out.println("This program will solve the quadratic formula for you.");
int cont = 0;
String back ="";
do
{
double a = Double.parseDouble(JOptionPane.showInputDialog("What is the value of a?"));
double b = Double.parseDouble(JOptionPane.showInputDialog("What is the value of b?"));
double c = Double.parseDouble(JOptionPane.showInputDialog("What is the value of c?"));
double det = (Math.pow(b,2))-(4 * a * c);
if (det < 0)
{
back ="The determinant is " + Math.sqrt(-det) +"i.";
System.out.print(back);
Quadratic.imaginary(a,b,det);
}
elseif (det >= 0)
{
back ="The determinant is " + det;
System.out.print(back);
Quadratic.real(a,b,det);
}
cont = JOptionPane.showConfirmDialog(null,"Would you like to solve another equation?");
for (int i = 0;i < back.length();i++)
System.out.print("\b");
for (int j = 0;j < back.length();j++)
System.out.print(" ");
for (int k = 0;k < back.length();k++)
System.out.print("\b");
}while(cont == 0);
}
publicstaticvoid imaginary(double a,double b,double det)
{
DecimalFormat formatter =new DecimalFormat("0.000");
det = Math.sqrt(-det);
double gmc = Quadratic.GCM(a,b,det);
a/=gmc;
b/=gmc;
det/=gmc;
if (det == 1)
JOptionPane.showMessageDialog(null,"X= " + a +" +- " + formatter.format(det) +"i");
else
JOptionPane.showMessageDialog(null,"X= ("+ a +" +- " + formatter.format(det) +"i)/" + (a * 2));
}
publicstaticvoid real(double a,double b,double det)
{
DecimalFormat formatter =new DecimalFormat("0.000");
det = Math.sqrt(det);
JOptionPane.showMessageDialog(null,"X= " + formatter.format((-b + det) / (a * 2)) +" , " + formatter.format((-b - det) / (a * 2)));
}
publicstaticdouble GCM(double a,double b,double det)
{
int x = 1;
double gcm = 1;
double small = 0;
if ((a <= b) && (a <= det))
small = a;
if ((b <= a) && (b <= det))
small = b;
if ((det <= a) && (det <= b))
small = det;
do
{
if ((a % x == 0) && (b % x == 0) && (det % x == 0))
gcm = x;
x++;
}while(x <= small);
return gcm;
}
}

