0

my program consist of solving equations and asking the user if he want to solve more equation, so even though i enter yes to continue but the loop terminate ,this is my code

 public static void main(String[] args) {

    String goAgain;

    double A, B, C, solution;
    Scanner scanner = new Scanner(System.in);
    System.out.println("This program will print a solution of an equation");
    System.out.println("of the form A*X*X + B*X + C = 0, where A, B, and");
    System.out.println("C are values that you enter.");

    do {
        System.out.println();
        System.out.println("Enter values of A, B and C : ");
        System.out.print(" A = ");
        A = scanner.nextDouble();
        System.out.print(" B = ");
        B = scanner.nextDouble();
        System.out.print(" C = ");
        C = scanner.nextDouble();
        System.out.println();
        try {

            solution = root(A, B, C);
            System.out.println("your solution is : " + solution);


        } catch (IllegalArgumentException e) {
            System.out.println("Sorry, I can't find a solution.");
            System.out.println(e.getMessage());

        }
        System.out.println("Do you want to solve another equation ? ");
        goAgain = scanner.next();
        System.out.println(goAgain);

    } while (goAgain == "yes");
}
  • 1
    oh yeah thanks , stupid me i forget that goAgain == "yes" compare the reference , i should use equals method instead .thanks again – Khatab Bouchra Jul 01 '15 at 02:41

1 Answers1

0

use .equals() Fucntion instead of == in while (goAgain == "yes");.
it should be while (goAgain.equals("yes");
Remember that goAgain == "yes" always returns false.

marc_s
  • 455
  • 1
  • 4
  • 15