Originally Posted by
mindlessn00b
Hey everyone I'm missing something small I'm trying to make a code to have you put anything in you like and then the output be the reverse of that here is the code.
import java.util.Scanner;
public class Reversed {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Reversed.reverseString(String);
}
public static String reverseString(String S){
Scanner Console = new Scanner(System.in);
System.out.println("What ever you enter will be reversed");
String str1 = Console.nextLine();
String str2 = reverseString(str1);
System.out.println(str2);
return S;
}
}
I get this error "Exception in thread "main" java.lang.Error: Unresolved compilation problem:
S cannot be resolved to a variable
at Reversed.main(Reversed.java:12)
I'm very new to programming and the teacher is very vague in his lectures any help is appreciated.
Do i need to make S a prior variable in the main method?
In your main method, you cannot name a variable the exact same way as a class. You can use lowercase, but you cannot tell it to return String;
Second, even if you could, you never defined String anyway. It needs to be defined somehow in the main method or else it won't work.
Also, perhaps Console has to be static.
Third, all you've done is call the method within itself. You've never reversed the String!
Fourth, even if you have, you're returning the parameter S, not the reversed String.
I'm currently baffled as to how to reverse a Sting too.