This program is meant to take the users input and tell them how many of each vowel there is. When "quit" is entered, the program does not break but instead just counts "quits" characters. Any ideas why? I have tried multiple ways of rephrasing the while statement but nothings seems to work.
import java.util.Scanner;
public class Count
{
public static void main (String[] args)
{
String phrase = ""; // a string of characters
int countBlank; // the number of blanks (spaces) in the phrase
int length; // the length of the phrase
char ch; // an individual character in the string
int countA, countE, countI, countO, countU ;
// Print a program header
System.out.println ();
System.out.println ("Character Counter");
System.out.println ();
// Read in a string and find its length
// a for loop to go through the string character by character
// and count the blank spaces
while(!phrase.equals("quit")){
length = phrase.length();
Scanner imp = new Scanner(System.in);
System.out.println("Enter a string: ");
phrase = imp.nextLine();
//put to lowercase in order to take uppercase ch's
phrase = phrase.toLowerCase();
if(phrase == "quit"){
break;
}
// set things equal to zero before starting count
countA = 0;
countE = 0;
countI = 0;
countO = 0;
countU = 0;
countBlank = 0;
//for loop to count
for(int i = 0; i < phrase.length();i++){
if(phrase.charAt(i) == ' '){
countBlank++;
}
if(phrase.charAt(i) == 'a'){
countA++;
}
if(phrase.charAt(i) == 'e'){
countE++;
}
if(phrase.charAt(i) == 'i'){
countI++;
}
if(phrase.charAt(i) == 'o'){
countO++;
}
if(phrase.charAt(i) == 'u'){
countU++;
}
}
// Print the results
System.out.println ();
System.out.println ("Number of blank spaces: " + countBlank);
System.out.println ();
System.out.println("Number of a's: " + countA);
System.out.println("Number of e's: " + countE);
System.out.println("Number of i's: " + countI);
System.out.println("Number of o's: " + countO);
System.out.println("Number of u's: " + countU);
}
}
}