if(string1 == string2) is not a good idea
it will be true only if string1 and string2 points to same String in memory
not if the strings are equals
the real method to use is if(string1.equals(string2))
It is sure that the String that you extract from sentence does not point to the same memory location than "a", "e", ....
Here is your corrected code.
I used a Scanner lot easier
Convert sentence into an array or char and then check if equals to 'a', 'e', .....
java
import java.util.*;
public class practice {
/*From book, page 170, problem 3.1*/
public static void main(String[] args) {
int vowel_count = 0;
int non_vowel_count = 0;
Scanner scan = new Scanner(System.in);
System.out.print("Please enter a sentence: ");
String sentence = scan.nextLine();
sentence.toLowerCase();//Convert to lower case
char[] check = sentence.toCharArray();
for (int i = 0; i < sentence.length(); i++){
if(check[i] == 'a' || check[i] == 'e' || check[i] == 'i' || check[i] == 'o' || check[i] == 'u')
{
++vowel_count;
}//end if
else
{
++non_vowel_count;
}//end else
}//end for*/
System.out.println("Vowel count is: "+vowel_count);
System.out.println("Non vowel count is: "+non_vowel_count);
}
}
In French "y" is a voyel I guess it is not in English