0

I'm doing a lab that requires a continuation question, but no matter what I do, the program always stops before accepting an answer. Here is my main method:

import java.util.Scanner;
import static java.lang.System.*;

public class Lab03b
{
public static void main( String args[] )
{
    Scanner scan = new Scanner(in);

    boolean ans = true;
    do{
        out.println("Enter the word to display:: ");
        String word = scan.nextLine();
        out.println("Enter the number of times to display:: ");
        int times = scan.nextInt();

        out.println("Do you wish to continue? (y/n):: ");
        String choice = scan.nextLine();

        WordPrinter.printWord(word,times);



        if (choice == "y" || choice == "Y")
        { ans = true;
        }
        else
        {
            ans = false;
        }
    } while(ans == true);

}
}

It references another class that goes through a basic loop to print out a word x amount of times. Any help is appreciated.

aevans
  • 1
  • 1
  • 1. What output do see in the console? 2. Show the code for Wordprinter.printWord. 3. The issue is almost certainly that you do reference equality checks in `if (choice == "y" || choice == "Y")` and not object equality checks. Change that line to `if (choice.equals("y") || choice.equals("Y"))` – Janus Varmarken Jul 05 '18 at 22:49
  • show the output? or at which point it stops? – Deadpool Jul 05 '18 at 22:50

0 Answers0