Αποσφαλμάτωση

Όσο τα προγράμματα που γράφουμε γίνονται πιο περίπλοκα αναγκαζόμαστε να χρησιμοποιούμε διάφορες τεχνικές για την αποσφαλμάτωσή τους. Μερικές από αυτές είναι: Το παρακάτω πρόγραμμα περιέχει εντολές εκτύπωσης κάτω από τον έλεγχο της μεταβλητής debug.
import gr.aueb.dds.BIO;

/*
 * Solve a qudratic equation ax^2 + bx + c = 0
 * Demonstrates the use of debug print statements
 */
class Quadratic {
        public static void main(String args[]) {
                double a, b, c;         // Equation factors
                double d;               // Discriminant
                boolean debug;          // True during development, false in production

                debug = false;

                BIO.print("a=");
                a = BIO.readDouble();
                BIO.print("b=");
                b = BIO.readDouble();
                BIO.print("c=");
                c = BIO.readDouble();

                if (debug == true) {
                        BIO.println("a=" + a);
                        BIO.println("b=" + b);
                        BIO.println("c=" + c);
                }
                if (a == 0) {
                        if (debug)
                                BIO.println("a == 0");
                        if (b == 0) {
                                BIO.println("No solutions");
                        } else {
                                // Not really quadratic; one root
                                BIO.print("r=");
                                BIO.println(-c / b);
                        }
                } else {
                        // Zero or two roots
                        if (debug)
                                BIO.println("a != 0");
                        d = b * b - 4 * a * c;
                        if (debug)
                                BIO.println("d=" + d);
                        if (d < 0) {
                                // Complex root
                                BIO.print("r=");
                                // Real part
                                BIO.print(-b / 2 / a);
                                BIO.print("+");
                                // Imaginary part
                                BIO.print(Math.sqrt(-d) / 2 / a);
                                BIO.println("i");
                        } else if (d == 0) {
                                // Two equal roots
                                BIO.print("r1=r2=");
                                BIO.println(-b / 2 / a);
                        } else {
                                BIO.print("r1=");
                                BIO.println((-b + Math.sqrt(d)) / 2 / a);
                                BIO.print("r2=");
                                BIO.println((-b - Math.sqrt(d)) / 2 / a);
                        }
                }
        }
}