Pretty new to Java programming, but I’m having trouble getting this to run. I want to read in a word using the StringBuffer class, then reverse it. I am fairly unfamiliar with importing Java libraries, so I’m not sure if I did that correctly. Either way, this is what I have. I tried to compile it (I’m working in the Terminal), but got a few compiler errors. Any help would be appreciated.
import java.util;
import java.io;
public class HW1A {
public static void main (String[] args) {
printBackwards();
}
public static void printBackwards (String[] args) {
StringBuffer backwards = new StringBuffer(args);
System.out.println(backwards.reverse());
}
}
I get the following complier errors:
HW1A.java:1: cannot find symbol
symbol : class util
location: package java
import java.util;
^
HW1A.java:2: cannot find symbol
symbol : class io
location: package java
import java.io;
Thanks.
Two corrections:
To import everything in java.io.
And:
To pass
argsto yourprintBackwardsmethod (you declared it correctly, but didn’t pass the variable).