我想做这个以便仍然可以检测到短输入,例如“Londo”和“Lon”,但是想要保持它的小并且基本上不需要复制和粘贴代码就可以使用它,有什么提示吗?谢谢。
if (Menu.answer1.equals("London"))
{
if (location.equals("London")) {
System.out.print(location + " ");
System.out.print(date + " ");
System.out.print(degrees + "C ");
System.out.print(wind + "MPH ");
System.out.print(winddirection + " ");
System.out.print(weather + " ");
System.out.println("");
}
最佳答案
您可以使用 startsWith()
String city = "London";
if (city.startsWith("Lon")) {
// do something
}
关于java - 字符串的额外 Java 输入验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55002154/