我需要通過命令行接話,將它們保存到一個數組,然後打印出來的話,像這樣:跳過一個字,打印下一個
input: asdf jkl qwerty dfs
output: - jkl qwerty dfs
asdf - qwerty dfs
asdf jkl - qwerty dfs
asdf jkl qwerty -
此外,如果用戶僅提供2個字,我應該達到同樣的結果。我不明白我會如何做到這一點,當提供的論據數量可能每次都會有所不同。 下面是我曾嘗試過的:
public static void main(String[] args)
{
String input1 = args[0];
String input2 = args[1];
String input3 = args[2];
String input4 = args[3];
String[] input = new String[4];
}
public static void printExceptOne(String[] exception, int x)
{
System.out.print("-");
System.out.print(" "+exception[1]);
System.out.print(" "+exception[2]);
System.out.println(" "+exception[3]);
}
}
你的想法是對的好老for循環會做的伎倆。但他想要一個不同的輸出。你的方法將輸出一些與他的問題的邏輯無關的東西 – Theo
@Theo感謝你的領導! –