1

I'm trying to make a program that checks if a phrase is a palindrome or not. I first ask how many phrases they want to check, and then proceed to ask the user to type in the phrase.

For some reason, when I put the amount of phrases to 1 while testing, the program skips over asking user for user input, and goes straight to printing out the results..

I'm guessing that the problem lies in the For loop used to ask for user input but I'm not sure..

I'll paste the main method of the program, as I don't think the other methods will be necessary for now..

public static void main(String [] args)
{
    //vars
    String userInput;
    //scanner
    Scanner in = new Scanner(System.in);
    //user input
    System.out.println("\t Palindrome Checker");
    System.out.print("How many do you want to test: ");
    int many = in.nextInt();
    //Array
    String [] a = new String[many];
    boolean [] det = new boolean[many];
    for(int i = 0; i < many; i++)
    {
        System.out.print("Input phrase one at a time: ");
        a[i] = in.nextLine();
    }

    //object
    RecursivePalindrome pal = new RecursivePalindrome();

    System.out.println();


    //call methods
    for(int i = 0; i < many; i++)
    {
        a[i] = RecursivePalindrome.helper(a[i]);
        det[i] = pal.palindrome(a[i]);
    }

    //print results
    System.out.println("=========================== Results ============================");
    System.out.println();
    System.out.printf(" %-30s%-11s%n", "Phrase or Word", "Palindrome?");


    for(int i = 0; i < a.length; i++)
    {

        System.out.printf(" %-30s%-11s%n", a[i], det[i]);
    }
}

0 Answers0