I want to be able to type the following into console of my IDE :
reverse("a b c d")
But currently I am only able to type
a b c d
How do I achieve this? I have tried using args[0] but I am getting an error.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String sentence = sc.nextLine();
reverse(sentence);
}
public static void reverse(String s){
String [] stringArray;
stringArray = s.split(" ");
int counter = stringArray.length;
for (String word : stringArray) {
counter -=1;
System.out.print(stringArray[counter]+" ");
}
}