gpt4 book ai didi

java - 如何将解决方案返回定义为 boolean 值?

转载 作者:行者123 更新时间:2023-12-01 11:56:47 27 4
gpt4 key购买 nike

我想检查输入是否是回文(向前和向后读取相同的方式),但我不熟悉 boolean 值。我不知道如何定义 boolean 值并作为 boolean 值返回。

这是我的测试代码

    @Test public void test5(){
code.Solution s = new code.Solution();
String input = "dad ";
int expected = true;
int actual = s.is Palindrome(input);
assert True("Expected was" +expected+"but the actual was" +actual , expected == actual);

}

我真的不知道如何定义我的解决方法。

最佳答案

boolean 数据类型只有两种状态:true 和 false。你的 isPalindrome 函数首先应该返回一个 boolean 值。一旦完成,测试将如下所示:

boolean expected = true;
boolean actual = s.is Palindrome(input);
assertEquals(expected, actual);

关于java - 如何将解决方案返回定义为 boolean 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28391127/

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