gpt4 book ai didi

JAVA- NETBEANS- 返回带有代码的方法

转载 作者:太空宇宙 更新时间:2023-11-04 13:01:36 25 4
gpt4 key购买 nike

第一篇文章在这里!

所以我有这段代码:

    static boolean getInternationalCalls() {
Scanner intercalls = new Scanner(System.in);
System.out.println("Would the customer like International Calls to be included within their minutes?");
System.out.println("If yes, please enter Y, if no please enter N below.");

Scanner scanner = new Scanner(System.in);

if (scanner.next().equalsIgnoreCase("Y") || scanner.next().equalsIgnoreCase("yes")) {
System.out.println("Internatinal Calls will be included");
} else if (scanner.next().equalsIgnoreCase("N") || scanner.next().equalsIgnoreCase("no")) {
System.out.println("International Calls will not be included");
} else {
System.out.println("Invalid character, please enter Y or N");

}

我自己很困惑,不知道如何编写它的返回语句

返回:

boolean interCalls = getInternationalCalls();

提前致谢! :)

最佳答案

我希望这不是你的作业杰米。你的方法遗漏了很多东西并且有语法错误。请使用像 eclipse 这样的 IDE,会容易得多。

static boolean getInternationalCalls() {
Scanner intercalls = new Scanner(System.in);
System.out.println("Would the customer like International Calls to be included within their minutes?");
System.out.println("If yes, please enter Y, if no please enter N below.");

Scanner scanner = new Scanner(System.in);
String input = null;
while (true) {
input = scanner.next();
if (input != null && (input.equalsIgnoreCase("Y") || input.equalsIgnoreCase("yes"))) {
System.out.println("Internatinal Calls will be included");
return true;
} else if (input != null && (input.equalsIgnoreCase("N") || input.equalsIgnoreCase("no"))) {
System.out.println("International Calls will not be included");
return false;
} else {
System.out.println("Invalid character, please enter Y or N");

}
}

}

关于JAVA- NETBEANS- 返回带有代码的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34887693/

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