我需要通过命令行接话,将它们保存到一个数组,然后打印出来的话,像这样:跳过一个字,打印下一个
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感谢你的领导! –