我需要在方法末尾傳遞字符串,以便直接在主方法中打印字符串,但是當我在下面這樣做時,我只收到這個 [Ljava.lang.String;@135fbaa4public static String businessLogic(String[] words) { for (String word : words) { char[] arrayWordInChar = word.toCharArray(); int wordLength = word.length(); for (int i = 0, j = wordLength - 1; i < j; ) { if (!Character.isAlphabetic(arrayWordInChar[i])) i++; else if (!Character.isAlphabetic(arrayWordInChar[j])) j--; else swapLetters(arrayWordInChar, i++, j--); } arrayWordInChar.toString(); } return Arrays.toString(words);}public class Main {public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] words = scanner.nextLine().split(" "); businessLogic(words); System.out.println(words);}}這個問題我已經困惑了快兩天了,請問是什么問題呢?
4 回答

紫衣仙女
TA貢獻1839條經驗 獲得超15個贊
你會得到“[Ljava.lang.String;@135fbaa4”,因為單詞是String[],你可以更改代碼如下。
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] words = scanner.nextLine().split(" ");
//businessLogic(words);
System.out.println(businessLogic(words));
}

白豬掌柜的
TA貢獻1893條經驗 獲得超10個贊
words
首先,通過以下方式向數組添加賦值words = businessLogic(words);
要打印 arraylist 元素,您可以執行以下操作之一:
System.out.println(Arrays.toString(words));
或者
for(String word : words){ System.out.println(word); }

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
BusinessLogic 方法返回一個字符串,但您沒有將其分配給任何 String 變量,并且在 System.out 中您將數組單詞打印為字符串。
System.out.println(businessLogic(words));
上面的行將打印您想要的輸出。
添加回答
舉報
0/150
提交
取消