我一直在试图弄清楚如何查看给定的句子是否是一个避免字母 E 的 lipogram。我已经达到了输入真/假陈述的地步,但它只输出“这句话是不是每次都避免字母 e 的 Lipogram,无论输入是否包含 e。我做错了什么?
boolean avoidsE = false, hasE = true, avoidsS = false, containsS = true;
for(int i = 0; i < sentence.length(); i++)
{
if (sentence.charAt(i) == 'e')
hasE = true;
else
avoidsE = false;
}
if (hasE = true)
System.out.println("This sentence is not a Lipogram avoiding the letter e. ");
else if (avoidsE = false)
System.out.println("This sentence is a Lipogram avoiding the letter e! ");
最佳答案
if (hasE == true) // "=" is to assign, you want to use "==" here to check
System.out.println("This sentence is not a Lipogram avoiding the letter e. ");
else if (avoidsE == false) //same here
System.out.println("This sentence is a Lipogram avoiding the letter e! ");
关于java - java中如何检查给定的句子是否避免了某个字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40053327/