gpt4 book ai didi

java - java中如何检查给定的句子是否避免了某个字母?

转载 作者:行者123 更新时间:2023-12-01 21:16:13 25 4
gpt4 key购买 nike

我一直在试图弄清楚如何查看给定的句子是否是一个避免字母 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com