Public class Example1
{
String fullname(String firstName, String secondName)
{
return firstName,secondName;
//return fullname(firstName,secondName); doesn't work either :(
}
public static void main(String[] args)
{
Example1 myname=new Example();
System.out.println(myname.fullname("John", "Wick");
}
}
雖然我在運行程序時遇到了一個錯誤。 你能幫我一下嗎?非常感謝如何在一種方法中返回2個字符串:字符串示例(String firstName,String secondName)
返回字符串 – TheLostMind
你有什麼期望在'的System.out.println(myname.fullname( 「約翰福音」, 「威克」))要打印的數組;'? – Pshemo
如果你想打印結果爲「John Wick」,那麼你應該把你的問題從「*如何返回兩個字符串*」變成更像「*如何返回一個包含兩個字符串的字符串*」的問題。否則,人們會建議返回而不是字符串一個對象,該對象將存儲兩個字符串(如數組,列表,集合或其他任何至少具有兩個字符串字段的類的實例)。 – Pshemo