The program is supposed to take a string input by the user and return it reversed. (ex "Hello" is input "olleH" is the output.) You do this by running the program like java ReverseCL2 Hello However, when no string is input with it, it prints an ArrayOutOfIndexException. I need it to instead print out what the user is supposed to do (Please input a string when running the code.) I have tried what is below and also if (args[0].equals(null)). Thanks in advance for any help :)
public class ReverseCL2
{
public static void main(String[] args)
{
String s = args[0];
String rev = "";
if (args[0].isEmpty())
{
System.out.println("Input a string to be reversed");
}
else
{
for (int i=0; i<s.length(); i++)
{
rev = s.charAt(i) + rev;
}
System.out.println(rev);
}
}
}