dimanche 12 mai 2019

Can you have a boolean expression repeat in a while loop?

I have found a way to make my program recognize if something is a palindrome or not, but when it is not, the program will not repeat.

I already have the boolean section of this implemented before my provided code.

Origianlly was set with if statements, wanted to replace with while but something like while (!yespalin(potentialp)) doesnt work either

    Scanner scan = new Scanner(System.in);      
    String potentialp;
    System.out.println("Please enter a potential palindrome: ");
    potentialp = scan.nextLine();

    while (yespalin(potentialp))
    {
    System.out.println("That string is a palindrome");  
    }
    while (!yespalin(potentialp))
    System.out.println("That string is not a palindrome, please enter another: ");  
    potentialp = scan.nextLine();

    }
    }   

I want the program to repeat if not a palindrome

Aucun commentaire:

Enregistrer un commentaire